Translate the following C code into assembly language progra
Translate the following C code into assembly language program. All variables are to be allocated space on the stack without using macros. In the program you are to use only registers %o0 and %o1. All variables are to be accessed from the stack such that at any time during program execution the latest values of the variables are located on the stack. You are to execute the statements in the order given. Do not try to optimize your code (i.e. do not remove nops).
char ca; short sb; int ic; char cd; short se; int ig;
ca = 17;
cd = ca + 23
ic = -63 + ca
ig = ic + cd
sb = ic / ca
se = cd * sb + ic
Note: - Run your programs using gdb to verify value of updated variables after each calculation
- Use correct versions of load and store commands for data of different sizes.
- Use correct versions of examine command of gdb to verify results: (ex: x/db for printing a byte memory variable in
signed decimal form)
Solution
HI ,
ca:
.zero 1
sb:
.zero 2
ic:
.zero 4
cd:
.zero 1
se:
.zero 2
ig:
.zero 4
mov ca,17
add ca,23
mov cd,ca
sub ca,63
mov ic,ca
add ic,cd
mov ig,ic
div ic,ca
mov sb,ic
mul cd,sb
add cd,ic
mov se,cd
