In: Computer Science
Assembly Language Programming Exercise
5. Listing File for AddTwoSum ( 5 pts )
Generate a listing file for the AddTwoSum program and write a
description of the machine code
bytes generated for each instruction. You might have to guess at
some of the meanings of the
byte values. Hint: Watch my tutorial and read a little bit of Ch
4.
The Answer is Assembly Language Programming Exercise
Listing File for AddTwoSum
This program calculates the sum of two integers
INCLUDE Irvine32.inc
ExitProcess PROTO
.data
sum DWORD 0
.code main PROC
mov eax,5 ; EAX=5
add eax,6 ; EAX=11
mov sum,eax ; sum=11
mov ecx,0
call ExitProcess
exit
main ENDP
END main
The listing file for the above source code is as follows:
INCLUDE Irvine32.inc
C.NOLIST
C.LIST
00000000 .code
00000000 main PROC
00000000 B8 00000005 mov eax.5 EAX=5
00000005 05 00000006 add eax,6 ; EAX=11
0000000A A3 00000000 mov sum,eax sum=11
0000000F B8 00000000 mov ecx,0 : ECX=0
00000014 E8 00000000 E call ExitProcess
00000019 main ENDP
END main
The .NOLIST directive disables listing this source code unless a .LIST directive is encounter'
The machine code generated by the assembler contains the line numbers against each instruction;
the instructions offset addresses, translated machine code etc.
The second-third leftmost columns tell the machine code bytes (in hexadecimal format) generated for the corresponding instruction.
For example,
B8 00000005 is the first instructions' bytes where 88 is the opcode and 00000005 is the value of the operand.
The above used opcodes are explained below:
1. 68: It is known as operation code as it represents a simple machine instruction to move a 32-bit integer say to EAX register
2. 05: It is used when a 32-bit value is added to a 32-bit register
3. A3: It is used when the value of a 32-bit register is moved to a 32-bit integer variable.
4. E8: It is used when a call is made to a procedure.