Homework 2
|
Modified: |
Downloads
Homework AssignmentUnderstanding how different data types are defined appropriate operations is critical to developing correct software systems. Two's complement and unsigned representations are commonly used for numeric representations while ASCII is the most common representation for characters. To understand the operation of the machine it is first necessary to understand the theory and practice on which that operation is based, exercises will provide practice in numeric representations and operations.
Program development using assembly language demands the use of a run-time debugger that allows step-by-step program execution.
There are 2 parts to the homework.
Part 1
The following gives the homework program and the assembler listing of the program.
The program defines data and a few instructions that access the data.
INCLUDE Irvine32.inc .data ; ----------------- Byte Values --------------------- byte1 BYTE 'A' byte2 SBYTE -128 byteArray BYTE 'A', 32, 41h, 00100010b helloWorld BYTE "Hello World",0 ; ----------------- Word Values --------------------- word1 WORD 65535 ; largest unsigned value word2 SWORD -32768 ; smallest signed value wordArray WORD 1,2,3,4,5 ; array of words ; --------------- DoubleWord Values -------------- dword1 DWORD 12345678h dword2 SDWORD -2147483648 dWordArray DWORD 11111111h, 22222222h, 33333333h ; ------- QuadWord and TenByte Values ------------ quadWord1 DQ 234567812345678h tenByte1 DT 1000000000123456789Ah ;------------------ Reals -------------------- real1 REAL4 -1.2 real2 REAL8 3.2E-260 real3 REAL10 4.6E4096 ; The following ranges were discovered by trial and error: ShortRealMax REAL4 9.9E+37 ; maximum exponent ShortRealMin REAL4 9.9E-38 ; minimum exponent LongRealMax REAL8 9.0E+307 ; maximum exponent LongRealMin REAL8 9.9E-308 ; minimum exponent ExtRealMax REAL10 9.9E+4931 ; maximum exponent ExtRealMin REAL10 9.9E-5199 ; minimum exponent ; ----------------- Pointers --------------------- ptrByteArray DWORD byteArray ; points to byteArray ptrWordArray DWORD wordArray ; points to wordArray .code main PROC mov al, byte1 mov ah, helloWorld[ 6 ] mov bx, word1 mov cx, wordArray[ 3 ] mov eDx, dword1 mov eSi, dWordArray[ 2 ] exit main ENDP END main |
00000000 .data ; ----------------- Byte Values --------------------- 00000000 41 byte1 BYTE 'A' 00000001 80 byte2 SBYTE -128 00000002 41 20 41 22 byteArray BYTE 'A', 32, 41h, 00100010b 00000006 48 65 6C 6C 6F helloWorld BYTE "Hello World",0 20 57 6F 72 6C 64 00 ; ----------------- Word Values --------------------- 00000012 FFFF word1 WORD 65535 ; largest unsigned value 00000014 8000 word2 SWORD -32768 ; smallest signed value 00000016 0001 0002 0003 wordArray WORD 1,2,3,4,5 ; array of words 0004 0005 ; --------------- DoubleWord Values -------------- 00000020 12345678 dword1 DWORD 12345678h 00000024 80000000 dword2 SDWORD -2147483648 00000028 11111111 dWordArray DWORD 11111111h, 22222222h, 33333333h 22222222 33333333 ; ------- QuadWord and TenByte Values ------------ 00000034 quadWord1 DQ 234567812345678h 0234567812345678 0000003C tenByte1 DT 1000000000123456789Ah 1000000000123456789A ;------------------ Reals -------------------- 00000046 BF99999A real1 REAL4 -1.2 0000004A real2 REAL8 3.2E-260 0A0F7D228322BAF5 00000052 real3 REAL10 4.6E4096 7527E1D52B1C853F14BF ; The following ranges were discovered by trial and error: 0000005C 7E94F56A ShortRealMax REAL4 9.9E+37 ; maximum exponent 00000060 0206C077 ShortRealMin REAL4 9.9E-38 ; minimum exponent 00000064 LongRealMax REAL8 9.0E+307 ; maximum exponent 7FE005419221015D 0000006C LongRealMin REAL8 9.9E-308 ; minimum exponent 0031CC12CFA686A2 00000074 ExtRealMax REAL10 9.9E+4931 ; maximum exponent 7FFED505D9D5BF6936E4 0000007E ExtRealMin REAL10 9.9E-5199 ; minimum exponent 00000000000000000000 ; ----------------- Pointers --------------------- 00000088 00000002 R ptrByteArray DWORD byteArray ; points to byteArray 0000008C 00000016 R ptrWordArray DWORD wordArray ; points to wordArray 00000000 .code 00000000 main PROC 00000000 A0 00000000 R mov al, byte1 00000005 8A 25 0000000C R mov ah, helloWorld[ 6 ] 0000000B 66| 8B 1D mov bx, word1 00000012 R 00000012 66| 8B 0D mov cx, wordArray[ 3 ] 00000019 R 00000019 8B 15 00000020 R mov eDx, dword1 0000001F 8B 35 0000002A R mov eSi, dWordArray[ 2 ] exit 0000002C main ENDP END main |
The debugger can be used to examine memory as the program executes.
For example, from the listing above, we can locate the variable offset (0x00000020) in memory, then find its value at the address (0x00404020) in memory:
00000020 12345678 dword1 DWORD 12345678h
dword1 variable is at address 00404020 and contains 12345678h.
0x00404000 41 80 41 20 41 22 48 65 6c 6c 6f 20 57 6f 72 6c A€A A"Hello Worl 0x00404010 64 00 ff ff 00 80 01 00 02 00 03 00 04 00 05 00 d.ÿÿ.€.......... 0x00404020 78 56 34 12 00 00 00 80 11 11 11 11 22 22 22 22 xV4....€...."""" 0x00404030 33 33 33 33 78 56 34 12 78 56 34 02 9a 78 56 34 3333xV4.xV4.šxV4 0x00404040 12 00 00 00 00 10 9a 99 99 bf f5 ba 22 83 22 7d ......š™™¿õº"ƒ"} 0x00404050 0f 0a bf 14 3f 85 1c 2b d5 e1 27 75 6a f5 94 7e ..¿.?..+Õá'ujõ”~ 0x00404060 77 c0 06 02 5d 01 21 92 41 05 e0 7f a2 86 a6 cf wÀ..].!’A.à.¢.¦Ï 0x00404070 12 cc 31 00 e4 36 69 bf d5 d9 05 d5 fe 7f 00 00 .Ì1.ä6i¿ÕÙ.Õþ... 0x00404080 00 00 00 00 00 00 00 00 02 40 40 00 16 40 40 00 .........@@..@@.Variables and registers can also be viewed individually in a watch window.
Turn in
Circle and label the following variables in the memory listing below:
- byte1
- helloWorld[ 6 ]
- word1
- wordArray[ 3 ]
- dword1
- dWordArray[ 2 ]
0x00404000 41 80 41 20 41 22 48 65 6c 6c 6f 20 57 6f 72 6c A€A A"Hello Worl 0x00404010 64 00 ff ff 00 80 01 00 02 00 03 00 04 00 05 00 d.ÿÿ.€.......... 0x00404020 78 56 34 12 00 00 00 80 11 11 11 11 22 22 22 22 xV4....€...."""" 0x00404030 33 33 33 33 78 56 34 12 78 56 34 02 9a 78 56 34 3333xV4.xV4.šxV4 0x00404040 12 00 00 00 00 10 9a 99 99 bf f5 ba 22 83 22 7d ......š™™¿õº"ƒ"} 0x00404050 0f 0a bf 14 3f 85 1c 2b d5 e1 27 75 6a f5 94 7e ..¿.?..+Õá'ujõ”~ 0x00404060 77 c0 06 02 5d 01 21 92 41 05 e0 7f a2 86 a6 cf wÀ..].!’A.à.¢.¦Ï 0x00404070 12 cc 31 00 e4 36 69 bf d5 d9 05 d5 fe 7f 00 00 .Ì1.ä6i¿ÕÙ.Õþ... 0x00404080 00 00 00 00 00 00 00 00 02 40 40 00 16 40 40 00 .........@@..@@.
Part 2
The algorithm (code) of the HW2 program moves data from variables to registers.
The execution can be followed using the debugger.
Program algorithm .code main PROC mov al, byte1 mov ah, helloWorld[ 6 ] mov bx, word1 mov cx, wordArray[ 3 ] mov eDx, dword1 mov eSi, dWordArray[ 2 ] exit main ENDP
Assignment
- Download HW2 project.
- Open Project.sln, Visual Studio should open the project.
- From the menu select: Debug | Start Debugging
- The debugger should pause at a breakpoint and display the register window at instruction:
mov al, byte1
- Clicking F11 key will execute the next instruction.
Turn in
Use the debugger to execute each instruction of the program algorithm.
List the variable offset, register effected, and resulting register values for each instruction executed.
For example, for the instruction and offset of variable helloWorld in the above listing:
Instruction Offset Register Value mov cl, helloWorld[ 4 ] 0000000A cl 6F or 'o' 00000006 48 65 6C 6C 6F helloWorld BYTE "Hello World",0
20 57 6F 72 6C
64 00
Instruction Offset Register Value mov al, byte1 mov ah, helloWorld[ 6 ] mov bx, word1 mov cx, wordArray[ 3 ] mov eDx, dword1 mov eSi, dWordArray[ 2 ]