In: Computer Science
Code using assembly language
Create a program using the Irvine32 procedures were the user can input a list of 32-bit unsigned integers an “x” number of times, then display these integers to the console in reverse order.
Hint: Use loops and PUSH & POP instructions.
Extra Challenge: Inform the user with a message what to do; also, tell them what they are seeing.
Consider the following code fragment:
somenum = 0FFh ; define constant to FF hex
MOV ah, somenum ; move (i.e. copy) to the AH register
somenum = 0AAh ; re-define constant to AA hex
MOV ah, somenum ; move to the AH register
The above is equivalent to:
MOV ah, 0FFh
MOV ah, 0AAh
In the above, we redefined the value of the constant somenum. The following code would be invalid:
somenum = 0FFh
MOV somenum, ah ; INVALID
This would be akin to trying to do:
MOV 0FFh, ah ; Move accumulator high to FF? Not valid since FF is a number, not a storage loc
1 title Add and Subtract (AddSub.asm)
2 ; This program adds and subtracts 32-bit integers.
3
4 INCLUDE Irvine32.inc
5 .code
6 main PROC
7 mov eax, 10000h ; EAX = 10000h
8 add eax, 40000h ; EAX = 50000h
9 sub eax, 20000h ; EAX = 30000h
10 call DumpRegs ; Display registers
11 exit
12 main ENDP
13 END main
Alternate version of AddSub
By including irvine32.inc, we are hiding a number of details. Here is a description of some of these details shown in this alternate version of the same program:
1 title Alternate Add and Subtract (AddSubAlt.asm)
2 ; This program adds and subtracts 32-bit integers.
3
4 .386
5 .MODEL flat,stdcall
6 .STACK 4096
7 ExitProcess PROTO, dwExitCode: DWORD
8 DumpRegs PROTO
9 .code
10 main PROC
11 mov eax, 10000h ; EAX = 10000h
12 add eax, 40000h ; EAX = 50000h
13 sub eax, 20000h ; EAX = 30000h
14 call DumpRegs ; Display registers
15 INVOKE ExitProcess, 0
12 main ENDP
13 END main