Author Topic: Showing a number  (Read 8084 times)

Offline sentes

  • Jr. Member
  • *
  • Posts: 2
Showing a number
« 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?

Code: [Select]
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

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Showing a number
« Reply #1 on: March 07, 2010, 05:43:19 PM »
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


Offline sentes

  • Jr. Member
  • *
  • Posts: 2
Re: Showing a number
« Reply #2 on: March 07, 2010, 06:18:20 PM »
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.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Showing a number
« Reply #3 on: March 07, 2010, 09:32:54 PM »
You're right. Sorry. That's what I get for posting on only one cup of coffee. :)

Thanks for the correction!

Best,
Frank