flat assembler
Message board for the users of flat assembler.

Index > DOS > addition of two digit number..help!!

Author
Thread Post new topic Reply to topic
manjaru



Joined: 22 Feb 2010
Posts: 1
manjaru 22 Feb 2010, 04:15
hello.. i dont know what the problem of my program..
my program is all about addition of two numbers..

here is my program in fasm:
Code:
org 100h

start:

mov ax,03h
int 10h

mov dx, message
mov ah,9
int 21h

xor ah,ah
int 16h
mov bh,al
;push bx

xor ah,ah
int 16h
mov bl,al
push bx

mov ah,9
int 21h

xor ah,ah
int 16h
mov ch,al

xor ah,ah
int 16h
mov cl,al

mov dx, result
mov ah,9
int 21h

add bl,cl
sub bl,30h

cmp bl,0ah
jae label_x

add bh,ch
sub bh,30h

;mov dl,bl
;mov dx, result
;mov ah,9
;int 21h


mov dl,bl
mov ah,2
int 21h

mov dh,bh
mov ah,2
int 21h
int 20h

label_x:
add bl,06h
pop cx
push cx
;shl bl,4

;mov dx,result
;mov ah,9
;int 21h

;add bl,30
;mov dl,bl
;mov ah,3
;int 21h


message: db 13,10,"enter 2 digit numbers: $"
result: db 13,10, "sum: $"    


hope you will solve it immedeatly.. thanks!! godbless Crying or Very sad
Post 22 Feb 2010, 04:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20522
Location: In your JS exploiting you and your system
revolution 22 Feb 2010, 05:26
Is this a homework assignment?
Post 22 Feb 2010, 05:26
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 22 Feb 2010, 08:28
manjaru wrote:
hope you will solve it immedeatly


NOT before you reveal what the problem is Neutral

Quote:
.. thanks!! godbless


Some hints:

1. Add comments
a) What register holds what ???
b) What call to INT $21 or $16 does what ???
2. Remove dead code
3. Recheck termination
Post 22 Feb 2010, 08:28
View user's profile Send private message Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 22 Feb 2010, 20:18
You need to add some comments on the instructions that are used. They help "debuggers" with actually knowing what the problem is with the code, or what the code does.


Quote:
Some hints:

1. Add comments
a) What register holds what ???
b) What call to INT $21 or $16 does what ???
2. Remove dead code
3. Recheck termination

_________________
meshnix
Post 22 Feb 2010, 20:18
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 23 Feb 2010, 06:36
Ultimately you want to collect input for each number into buffer.
Then process it and print the result.
That way you wouldnt be limited to numbers less than 99 as result.

Anyway, i put some notes and made it work, somehow :S
Code:
; make .COM program
org 100h

; enter 80*25 video mode
mov ax,03h
int 10h

; print prompt to enter first 2 digit number
mov dx, message
mov ah,9
int 21h

; get 10'ths of first number
xor ah,ah
int 16h
mov bh,al

; get 1'ths of first number
xor ah,ah
int 16h
mov bl,al

; print prompt to enter second 2 digit number
mov ah,9
int 21h

; get 10'ths of second number
xor ah,ah
int 16h
mov ch,al

; get 1'ths of second number
xor ah,ah
int 16h
mov cl,al

; print header for results
mov dx, result
mov ah,9
int 21h

; -statecheck-
;
; BH = 10.ths of first number
; BL = 1'ths of first number
; CH = 10'ths of second number
; CL = 1'ths of second number
;

; add numbers together (very cheezy)
add bl,cl
sub bl,30h

add bh,ch
sub bh,30h

cmp bl,'9'
jle label_x
inc bh
label_x:

; print 10'ths of result
mov dl,bh
mov ah,2
int 21h

; print 1'ths of result
mov dl,bl
mov ah,2
int 21h

; wait for user to press any key
xor ah,ah
int 16h

; exit back to operating system
int 20h

; dos strings Smile
message: db 13,10,"enter 2 digit numbers: $"
result: db 13,10, "sum: $"
    

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 23 Feb 2010, 06:36
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.