Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

plz solve this problem. For this exercise, we will examine the code generated by

ID: 3819444 • Letter: P

Question

plz solve this problem.

For this exercise, we will examine the code generated by GCC for functions that have structures as arguments and return values, and from this see how these language features are typically implemented. The following C code has a function word sum having structures as argument and return values, and a function prod that calls process: 1 typedef struct long a C21; long *p; strA 6 typedef struct f long u [2]; long 9 strB 10 11 str process (strA s) f strB r 12 r. u [0] s. a [1] [11 a [0] r, u 14 *s.p r.q. 15 return r 17 18 19 long eval long x, long y, long z) f strA s 20 s a[01 21 s. a[1] 23 str r process (s) 24

Explanation / Answer

section   .text
global _start ;must be declared for using gcc
  
_start:   ;tell linker entry point
mov   ecx,'4'
sub ecx, '0'
  
mov    edx, '5'
sub edx, '0'
  
call sum ;call sum procedure
mov    [res], eax
mov   ecx, msg  
mov   edx, len
mov   ebx,1   ;file descriptor (stdout)
mov   eax,4   ;system call number (sys_write)
int   0x80   ;call kernel
  
mov   ecx, res
mov   edx, 1
mov   ebx, 1   ;file descriptor (stdout)
mov   eax, 4   ;system call number (sys_write)
int   0x80   ;call kernel
  
mov   eax,1   ;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
res resb 1

; Save the AX and BX registers in the stack
PUSH AX
PUSH BX

; Use the registers for other purpose
MOV   AX, VALUE1
MOV    BX, VALUE2
...
MOV    VALUE1, AX
MOV   VALUE2, BX

; Restore the original values
POP   AX
POP   BX
Example
The following program displays the entire ASCII character set. The main program calls a procedure named display, which displays the ASCII character set.

section   .text
global _start ;must be declared for using gcc
  
_start:   ;tell linker entry point
call display
mov   eax,1   ;system call number (sys_exit)
int   0x80   ;call kernel
  
display:
mov ecx, 256
  
next:
push ecx
mov eax, 4
mov ebx, 1
mov ecx, achar
mov edx, 1
int 80h
  
pop ecx  
mov   dx, [achar]
cmp   byte [achar], 0dh
inc   byte [achar]
loop next
ret
  
section .data
achar db '0'