Convert the following C program to assembly. Test code checks it. 1 uint16_t u16
ID: 3906542 • Letter: C
Question
Convert the following C program to assembly. Test code checks it. 1 uint16_t u16_a; 2 uint16_t u16_b; 3 uint16_t u16_c; 4 5 void translation_approach_ex_1(void) 6 u16 c = u16 a + u16 b; 7 // End Data .bss First define a variable named_u16_a , then define _u16_b , then define_u16_c, all of which occupy two bytes of memorv. Make all variables visible to C The variable below is used by the test code; you may ignore it u8_test: .space 1 .global _u8_test Code .text Write assembly which implements the C given above Save and runExplanation / Answer
Assembly code:
segment .bss
u_16_a resb 2
u_16_b resb 2
u_16_c resb 1
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov ecx,u_16_a
sub ecx, '0'
mov edx, u_16_b
sub edx, '0'
call sum ;call sum procedure
mov [u_16_c], eax
mov ecx, msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,u_16_a ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx, u_16_c
mov edx, u_16_b
mov ebx, 1 ;file descriptor (stdout)
mov eax, u_16_a ;system call number (sys_write)
int 0x80 ;call kernel
mov eax, u_16_b ;system call number (sys_exit)
int 0x80 ;call kernel
sum:
mov eax, ecx
add eax, edx
add eax, '0'
ret
section .data
msg db "The sum is:", 0xA,0xD
len equ $- msg
segment .bss
u_16_c resb 1