please help in spark assembly ObjectiveTo learnhow touse loo
please help in spark assembly
Objective:To learnhow touse loops, if-statement, to representvariables and array in the stack, to load and store data from and into the stack and to use gdb.
Requirements:
1.Translate the following C code into SPARC assembly language program. All variablesare to be allocated space on the stack without using macros. In the program you aretouse only registers %o0 and %o1. All variables are to be accessed from the stacksuch that at any time during program execution the latest values of the variables are located on the stack. You are toexecute the statements in the order given. Donot 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
Answer:
MIPS Assembly Language Code:
.zero 1
 main:
 push rbp
 mov rbp, rsp
 mov BYTE PTR [rbp-1], 17
 movzx eax, BYTE PTR [rbp-1]
 add eax, 23
 mov BYTE PTR [rbp-2], al
 movsx eax, BYTE PTR [rbp-1]
 sub eax, 63
 mov DWORD PTR [rbp-8], eax
 movsx edx, BYTE PTR [rbp-2]
 mov eax, DWORD PTR [rbp-8]
 add eax, edx
 mov DWORD PTR [rbp-12], eax
 movsx ecx, BYTE PTR [rbp-1]
 mov eax, DWORD PTR [rbp-8]
 cdq
 idiv ecx
 mov WORD PTR [rbp-14], ax
 movsx dx, BYTE PTR [rbp-2]
 movzx eax, WORD PTR [rbp-14]
 imul eax, edx
 mov edx, DWORD PTR [rbp-8]
 add eax, edx
 mov WORD PTR [rbp-16], ax
 mov eax, 0
 pop rbp
 ret
 __static_initialization_and_destruction_0(int, int):
 push rbp
 mov rbp, rsp
 sub rsp, 16
 mov DWORD PTR [rbp-4], edi
 mov DWORD PTR [rbp-8], esi
 cmp DWORD PTR [rbp-4], 1
 jne .L5
 cmp DWORD PTR [rbp-8], 65535
 jne .L5
 mov edi, OFFSET FLAT:std::__ioinit
 call std::ios_base::Init::Init()
 mov edx, OFFSET FLAT:__dso_handle
 mov esi, OFFSET FLAT:std::__ioinit
 mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
 call __cxa_atexit
 .L5:
 nop
 leave
 ret
 push rbp
 mov rbp, rsp
 mov esi, 65535
 mov edi, 1
 call __static_initialization_and_destruction_0(int, int)
 pop rbp
 ret


