I'm using assembly 8086 16BIT with tasm assembler. I'm trying to print an int variable, and to do so I need to converet my variable contant to string. I tried to build a procedure that do this without success. its completely wrong and not working.
can you help me build this/explain how to build this?
Thanks guys!
This is my base code right now:
stepCounter db 0
push offset stepCounter ; Copy the OFFSET of "parameter" into the stack
call toString
proc toStringPrint
push bp
mov bp, sp
mov ax, [bp + 4] ;number
div 10; div number(in ax) by 10
mov [bx], ah
;mov dx, []
;mov ah, 9h
;int 21h
pop bp
ret 4
endp toString
EDIT
thanks! this is my code now: but its still not print nothing
proc toStringPrint
push bp
mov bp, sp
mov si, [bp+4];number
mov ax, [si]
divide:
cmp al, 0
je Print
mov cl, 10
div cl; div number(in ax) by 10
mov [bx], ah
dec bx
jmp divide
Print:
mov dx, [bp + 6]
mov ah, 9h
int 21h
pop bp
ret 4
endp toStringPrint
EDIT 2 This is the current code, still crash the application and always print 219:
stepCounter dW 0
;this is how i call the PROC:
mov cx, [stepCounter]
push cx
call toStringPrint
proc toStringPrint
push bp
mov bp, sp
mov si, [bp+4] ;number location in memory( I think )
mov ax, [si]
mov cl, "$"
mov [bx], cl
divide:
mov ah, 0
mov cl, 10
div cl ; div number(in ax) by 10
dec bx
add ah, 48 ;Make into a character
mov [bx], ah
cmp al, 0
jne divide
Print:
mov dx, bx
mov ah, 9h
int 21h
pop bp
ret 4
endp toStringPrint