Assembly Line
Problem 1
- Stores
"x: "
in registerr1
. - Prints the value in register
r1
, which is"x: "
. - Prompts the user to input a value for x, and stores that value in
r2
. - Stores
"y: "
in registerr1
. - Prints the value in register
r1
, which is"y: "
. - Prompts the user to input a value for y, and stores that value in
r3
. - If the values in
r2
andr3
are equal (i.e., the two numbers the user provided as input are equal), then jump to line 11. - Stores
"x is not equal to y"
in registerr1
. - Prints the value in register
r1
, which is"x is not equal to y"
. This line only executes if the condition on line 7 was false; otherwise, this line will be skipped. - Exit the program, since the desired output has been printed.
- If the program reaches this line, then the values in
r2
andr3
must be equal. This line stores"x is equal to y"
in registerr1
. - Prints the value in register
r1
, which is"x is equal to y"
. This line only executes if the condition on line 7 was true; otherwise, we would exit the program before reaching this line. - Exit the program, since the desired output has been printed.
Problem 2
1 SET r1 "x: "
2 PRINT r1
3 INPUT r2
4 SET r1 "y: "
5 PRINT r1
6 INPUT r3
7 JUMPEQ r2 r3 15
8 JUMPLT r2 r3 12
9 SET r1 "x is greater than y"
10 PRINT r1
11 EXIT
12 SET r1 "x is less than y"
13 PRINT r1
14 EXIT
15 SET r1 "x is equal to y"
16 PRINT r1
17 EXIT
Problem 3
1 SET r1 "Number: "
2 PRINT r1
3 INPUT r2
4 SET r3 0
5 JUMPEQ r2 r3 11
6 SET r4 1
7 SET r1 "cough"
8 PRINT r1
9 ADD r3 r3 r4
10 JUMPLT r3 r2 8
11 EXIT
Problem 4
callq
, since it is the instruction that appears to take names of functions (e.g., get_int
or printf
) as its argument.
Problem 5
There are three reasonable answers to the question:
jge
. This instruction jumps the program to a particular label in the assembly code based on whether a condition is true. If the jump takes place, one string is printed; otherwise, a different string is printed.cmpl
. This instruction compares two values. Depending on the result of the comparison, the program can then decide which string to print.movabsq
. This instruction moves one value from one location to another; in this case, moving a string into a register so that the call toprintf
can print that string. This decision ultimately determines what stringprintf
prints.