NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: sentes on March 07, 2010, 02:15:20 PM
-
I've coded something like that. It's supposed to show 25499, but it doesn't. It shows 25309. What's wrong with this code?
org 100h
start:
mov ax, [liczba]
xor dx, dx
mov cx, 10000
div cx
or al, '0'
call showChar
mov ax, dx
xor dx, dx
mov cx, 1000
div cx
or al, '0'
call showChar
mov ax, dx
mov cl, 100
div cl
or al, '0'
mov cl, ah
call showChar
mov al, cl
xor ah, ah
mov cl, 10
div cl
or ax, '0'
mov cl, ah
or cl, '0'
call showChar
mov ah, 2
mov dl, cl
int 21h
;Terminate process
mov ax, 4c00h
int 21h
showChar:
mov ah, 2h
mov dl, al
int 21h
ret
liczba dw 25499
-
Looks to me, without testing it, like you switch from "div cx" to "div cl" too soon. After dividing by 1000, your remainder should be 499, right? Won't all fit in al! You need to use cx, one more time. You're on the right track.
Best,
Frank
-
Thanks for help but the problem was differrent. Changing for div cl wasn't wrong. I just didn't save the dx register which was overwritten by
showChar function.
-
You're right. Sorry. That's what I get for posting on only one cup of coffee. :)
Thanks for the correction!
Best,
Frank