In: Computer Science
HCS12 Assembly code please.
Translate the following code into assembly. Allocate each variable on the stack. Simulate your
program and screenshot the final value of the variables in memory.
{
char A,B,C;
int F;
A = 2;
B = 6;
C =
-
10;
F = (A + B)*C;
C = F
+10
}
Below is the program converted into assembly language.
main:
        push    rbp
        mov     rbp, rsp
        mov     BYTE PTR [rbp-1], 2
        mov     BYTE PTR [rbp-2], 6
        mov     BYTE PTR [rbp-3], -10
        movsx   edx, BYTE PTR [rbp-1]
        movsx   eax, BYTE PTR [rbp-2]
        add     edx, eax
        movsx   eax, BYTE PTR [rbp-3]
        imul    eax, edx
        mov     DWORD PTR [rbp-8], eax
        mov     eax, DWORD PTR [rbp-8]
        add     eax, 10
        mov     BYTE PTR [rbp-3], al
        mov     eax, 0
        pop     rbp
        ret
This is the output log of the following asm program and the final values of variables.
ASM generation compiler returned: 0
Execution build compiler returned: 0
Program returned: 0
2,6,-70,-80
PS: The statement I added to know the final values of variables(converted into C) : printf("%d,%d,%d,%d",A,B,C,F);
So, A=2, B=6, C=-70, F=-80