Skip to main content
gamedev.net
🔒 Locked

asm problem :/

Started by Sir Valeq Feb 26, 2005 at 7:22 AM 0 replies 700+ views
Original Post
Sir Valeq
Sir Valeq
Hi I've just begun learning asm and encountered my first problem. Why does this code not work? It is supposed to do a simple calculation: d/(b-c)*(a+b)

                .MODEL  SMALL

ASSUME   DS:Dane, CS:Kod, SS:Stosik

Dane            SEGMENT

a               DB      20
b               DB      10
c               DB      5
d               DB      3

Dane            ENDS

Kod             SEGMENT                

Start:
                mov     ax, Dane
                mov     ds, ax

                
                mov	bx, WORD PTR b
                sub	bx, WORD PTR c
                mov	ax, WORD PTR d
                div	bl
                mov	bx, WORD PTR a
                add	bx, WORD PTR b
                mul	bx             
                
                mov	dx, ax
                mov     ah, 02h              
                int	21h

                mov     ax, 4C00h
                int     21h

Kod             ENDS

Stosik          SEGMENT  STACK

                DB      512 DUP (?)

Stosik          ENDS

END    Start
It compiles well, but shows nothing when executed.
--------------"We cannot all be masters." - William Shakespeare
doynax
doynax
You're loading word sized data from byte variables (forced through the use of WORD PTR). Try changing the data definitions to use DW instead.
The BIOS interrupt used (21, 2) only prints single ASCII characters in DL, not integers. You'll have to convert the result into a string of digits manually instead. This is usually achieved through successive divisions by 10, leaving the remainder plus the ASCII value of '0' as the next digit to be printed.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.