Assignment 1
Assignment 1
Assignment 1
This assignment must be completed and submitted by moodle no later than Tuesday 19th of November
2024, 9am. The assignment must be solved and submitted individually.
Exercise 1
Determine the values of registers %rax, %rbx and %rcx after the execution of the following programs.
1. (10 points)
Exercise 2
(25 points)
Write an ASM program that, assuming that an input is received in register %rdi, prints out “Zero”, “Positive
Even”, “Positive Odd”, “Negative Even”, or “Negative Odd”, according to the sign and parity of the input.
You can use a write system call. You may test your program by prepending as a first instruction the following:
Exercise 3
(30 points)
Assuming that a string is defined in the .data section, containing solely lowercase letters and white spaces,
write an ASM program that converts the string to camel case format, i.e., replacing every white space and
following lower case character, by the corresponding upper case character (removing the white space). You
may use any looping strategy, and assume that the result is stored in a different memory location in the .data
section. Test your program with different input strings, including strings with leading and trailing spaces, and
multiple spaces separating words. Comment your code to explain how it works.
Some examples of inputs and the corresponding expected outputs are the following:
Input Output
"hello world" "helloWorld"
" hello world" "helloWorld"
"hello world " "helloWorld"
"hello world" "helloWorld"
" hello world " "helloWorld"
Exercise 4
(25 points)
long f(long n) {
int i = 0;
while (n > 1) {
if (n % 2 == 0) {
n = n / 2;
}
else {
n = n * 3 + 1;
}
i++;
}
return i;
}
Write an ASM program that implements this function, assuming that the input n is received in %rdi, and
the output is written to %rax. Test your program with different values for the input, and include appropriate
comments in your code to explain how it works.
Some examples of inputs and the corresponding expected outputs are the following:
Input Output
1 0
5 5
10 6
15 17
20 7
25 23
30 18