;************************************************* ; Purpose: To show simple addition and subtraction ; using 32-bit registers ;************************************************* TITLE AddSub1.asm - Protected Mode INCLUDE Irvine32.inc .code main PROC mov eax, 2h ; EAX = 2h add eax, 3h ; EAX = 3h sub eax, 1h ; EAX = 4h call DumpRegs exit main ENDP END main
make32 AddSub1If no errors exist, this produces an executable called AddSub1.exe. Executing the program will dump the registers EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP, EIP, EFL, CF SF ZF OF.
So what might a 16-bit program to do the same thing look like?
;*************************************************
; Purpose: To show simple addition and subtraction
; using 16-bit registers and a data
; segment
;*************************************************
INCLUDE Irvine16.inc
.data
v1 dword 2h
v2 dword 4h
v3 dword 1h
rslt dword ?
.code
main PROC
mov ax, @data ; place the address of data seg in ax
mov ds, ax ; initialize DS to address of data seg
mov eax,v1 ; place 2h in eax
add eax,v2 ; add 4h to eax
sub eax,v3 ; subtract 1h from eax
mov rslt,eax ; store the result (5h)
call DumpRegs ; display the registers
exit
main ENDP
END main
Between now and the next time we get together, get the 16-bit version of this program running using Visual Studio 6.0. Here are the steps: