In: Computer Science
2) Draw a line between each of the IA32 assembler routines on the left and its equivalent C function on the right. (If there is no matching C function, do not draw a line.):
|
|
(b) Consider the following IA32 assembly language code fragment:
.data
.align 4
A: .long 10, 20, 30, 40, 50
.text
main: <code>
Determine the decimal value stored in register %eax if <code> in the above code fragment is replaced by each of the following:
i) movl $A, %ebx
movl 4(%ebx), %eax
ii) movl $2, %ecx
movl A(,%ecx, 4), %eax
iii) movl $24,
%eax
sarl $2, %eax
iv) movl $4, %ecx
leal 4(%ecx,%ecx,4), %eax
SOLUTION:
2)
(b)
(i)
movl $A, %ebx ;Move the address of A into register %eax
movl 4(%ebx), %eax ;Add 4 byte (one memory unit in 'Long' type ) to address stored in %ebx and move the contents of this address into %eax.
Value stored in %eax is 20
(ii)
movl $2, %ecx ;Move number 2 into register %ecx
movl A( , %ecx, 4), %eax ;Multiply content on %ecx with 4. Add the result to the address of A (struct_base) This gives the resultant address and move the contents of this address into %eax.
Value stored in %eax is 30
(iii)
movl $24, %eax ;Move number 24 into register %eax
sarl $2, %eax ;Arithmetic right shift to content in %eax for 2 times.
ie, (24)10 = (0001 1000)2
First shift -> 00001100
Second shift -> (00000110)2 = (6)10
Value stored in %eax is 6
(iv)
movl $4, %ecx ;Move number 4 into register %ecx
leal 4( %ecx, %ecx, 4), %eax ;Multiply content on %ecx with 4, add this with content on %ecx, and add 4 to it. This gives the resultant address
Resultant Address = (4 * %ecx) + %ecx + 4 = (4 * 4) + 4 + 4
Value stored in %eax is 24
**Fell free to ask any queries in the comment section. I am happy to help you. if you like our work, please give Thumbs up**