Start New Discussion within our Software Development Community
TITLE: Register Dump (RegDump.asm)

;------------------------------------------------------------
; Name: 
;
; Filename: RegDump.asm
;
; Project #: 2
;
; Completed: February 09, 2003
;
; Description: My second assembly program. Will demonstrate
;              dumping the registers. Demonstrates problems
;              from Assembly Language For Intel-Based Computers,
;              4th Ed. by Kip R. Irvine. Problems are #1 on pg.
;              96, #1 on pg. 133 and #7 and #8 on pg. 134.
;
; Reference:   Assembly Language For Intel-Based Computers,
;              4th Ed. by Kip R. Irvine
;------------------------------------------------------------
INCLUDE Irvine32.inc

.data
val1 SDWORD 8
val2 SDWORD -15
val3 SDWORD 20
source   byte "This is the source string",0
target   byte  SIZEOF source DUP(0)
nameSize = ($ - source) - 1
msgIntro byte "This is My Name's second assembly program and I will",0dh,0ah
         byte "demonstrate how to dump the registers using questions 1",0dh,0ah
         byte "on page 96, question 1 on page 133, and question 7 and 8",0dh,0ah
         byte "on page 134.",0dh,0ah
         byte 0dh,0ah,0
msg1     byte "------------------------------------",0dh,0ah
         byte "Demonstrating question 1 on page 96.",0dh,0ah
         byte "------------------------------------",0dh,0ah,0
msg2     byte "-------------------------------------",0dh,0ah
         byte "Demonstrating question 1 on page 133.",0dh,0ah
         byte "-------------------------------------",0dh,0ah,0
msgAdd   byte "Adding 0FFh and 1h in register al to set carry flag",0dh,0ah,0
msgSub   byte "Subtracting 3h from 2h in register ax to set carry flag",0dh,0ah,0
msg3     byte "-------------------------------------",0dh,0ah
         byte "Demonstrating question 7 on page 134.",0dh,0ah
         byte "-------------------------------------",0dh,0ah,0
msgExpr  byte "Solving expression EAX = -val2 + 7 - val3 + val1",0dh,0ah,0
msg4     byte "-------------------------------------",0dh,0ah
         byte "Demonstrating question 8 on page 134.",0dh,0ah
         byte "-------------------------------------",0dh,0ah,0
normOrd  byte "Normal order:",0dh,0ah,0
revOrd   byte "Reverse order:",0dh,0ah,0

.code
main PROC
;///////Intro Message/////////////////////////////////
	mov edx,OFFSET msgIntro ;intro message into edx
        call WriteString        ;display msgIntro

;///////Question 1 on page 96/////////////////////////
        mov edx,OFFSET msg1     ;message 1 into edx
        call WriteString        ;display msg1
	mov eax, 1000h		;1000h
	mov ebx, 4000h		;4000h
	mov ecx, 2000h		;2000h
	sub ebx, eax            ;4000h-1000h = 3000h
	sub ebx, ecx            ;3000h-2000h = 1000h
	call DumpRegs		;display the registers
	call WaitMsg            ;use call WaitMsg from page 146 to pause

;///////Question 1 on page 133/////////////////////////
        mov edx,OFFSET msg2     ;message 2 into edx
        call WriteString        ;display msg2

        ;Add to get carry flag
        mov edx,OFFSET msgAdd   ;message Add into edx
        call WriteString        ;display msgAdd
        mov al,0FFh
        add al,1h               ;al=100h CF=1 Because result of add is 100 so only 00
                                ;can go in the al register so the 1 is carried over
        call DumpRegs           ;display registers

        ;//Subtract to get carry flag
        mov edx,OFFSET msgSub   ;message Sub into edx
        call WriteString        ;display msgSub
        mov ax,2h
        sub ax,3h                ;ax=FFFFh CF=1 Because larger int - from smaller int
        call DumpRegs           ;display the registers
        call WaitMsg            ;use call WaitMsg from page 146 to pause

;///////Question 7 on page 134/////////////////////////
	mov edx,OFFSET msg3     ;message 3 into edx
	call WriteString        ;display msg3
	mov edx,OFFSET msgExpr  ;message Expr into edx
        call WriteString        ;display msgExpr
        mov eax,val2            ;mov val2 FFFFFFF1h in eax
        neg eax                 ;change sign of val2 in eax 0Fh
        add eax,7               ;add seven to eax 016h
        sub eax,val3            ;subtract val3 from eax 02h
        add eax,val1            ;add val1 to eax 0Ah
        call DumpRegs           ;display the registers
        call WaitMsg            ;use call WaitMsg from page 146 to pause

;///////Question 8 on page 134/////////////////////////
	mov edx,OFFSET msg4     ;message 4 into edx
	call WriteString        ;display msg4

	;//Using part of (CopyStr.asm) Pg.130-131 for reference
	mov esi,0               ;index register
        mov ecx,SIZEOF source   ;loop counter

	L1: ;//Loop
        mov al,source[esi]      ;get a character from source
        mov target[esi],al      ;store it in the target
        inc esi                 ;move to next character
        loop L1                 ;repeat for entire string

        ;//Print in normal order
        mov edx,OFFSET normOrd  ;message normOrd into edx
	call WriteString        ;display normOrd
	mov esi,OFFSET target   ;offset of variable
	mov ebx,1               ;byte format
	mov ecx,SIZEOF target-1 ;counter
	call DumpMem            ;display the block of memory in hex
        call WaitMsg            ;use call WaitMsg from page 146 to pause

        ;//Using part of (RevString.asm) Pg.157-158 for reference
        ;//Print in reverse order
        mov edx,OFFSET revOrd   ;message revOrd into edx
	call WriteString        ;display revOrd
        mov ecx,nameSize        ;push source on the stack
        mov esi,0

        L2: ;//Loop
        movzx eax,source[esi]   ;get character from source[esi] put in eax
	push eax                ;push on stack
	inc esi
	loop L2

        ;//Pop name in reverse and store in array
	mov ecx,nameSize
	mov esi,0

	L3: ;//Loop
	pop eax                 ;get characters form eax
	mov source[esi],al      ;store in string
	inc esi
	loop L3

	mov esi,OFFSET source   ;offset of variable
	mov ebx,1               ;byte format
	mov ecx,SIZEOF source-1 ;counter
	call DumpMem            ;display the block of memory in hex

	exit
main ENDP
END main