Hello,
I'm having trouble getting multiple procedures to work together... they both work fine alone... but the second one (WriteInteger) messes up when incorporated into code with the first (WriteString) and I'm trying to understand why.
Here's the code I'm looking at:
org 0x100
section .data
Constant0 db "hello"
Constant0length equ 5
Newline db 13, 10
Newlinelength equ 2
Constant2 equ 1 ; trouble here (do I make it a dd, dw, or just leave it as equ?)
section .text
and esp, 0FFFFh
push Constant0length
push Constant0
Call WriteString
push Newlinelength
push Newline
Call WriteString
push Constant2 ; trouble here?
Call WriteInteger
push Newline
push Newlinelength
Call WriteString
mov ax, 0x4c00
int 0x21
WriteString:
mov si, [esp + 2]
mov cx, [esp + 4]
strtoconsole:
lodsb
mov dl, al
mov ah, 0x06
int 0x21
loop strtoconsole
.end:
ret 4
WriteInteger: ; trouble here?
mov eax, [esp + 2] ; move number into eax.
mov ecx, 10 ; move 10 into ecx
xor bx, bx ; zero out bx
divide:
xor edx, edx ; zero out edx
div ecx ; divide eax by ecx
push dx ; push dx (digit to print)
inc bx ; increment bx
test eax, eax ; test eax for zero
jnz divide ; if eax isn't zero then divide further
mov cx, bx ; move bx (number of digits) to cx (code counter)
outputDigit:
pop ax ; pop ax
add al, '0' ; add integer '0' to al to make al an regular text (numeric) character.
mov dl, al ; move al into dl.
mov ah, 0x06 ; character ouput.
int 0x21 ; execute character output
loop outputDigit ; loop until cx is zero
ret 2
As always, thanks in advance for any help you can give,
Dominick