|
Forum
|
|
|
Addtion of two digits - HELP, I dont know what the problem of my program is; my program is all about addition of two numbers
|
|
| manjaru |
|
New Member

Group: Members
Posts: 1
Member No.: 32159
Joined: 20-February 10

|
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 this prog. will be solved.. godbless.. thanks
|
| |
|
|
|
| shoorick |
|

Extremely Active Member
     
Group: Admins
Posts: 2301
Member No.: 160
Joined: 22-June 04

|
you should run your code under debugger first to see what you do in real. i see you try to provide BCD addition, but you are adding ASCII codes and only then substructing 30h: it's wrong. you have to substract 30h from both codes first, or substract 60h after. next: if your bl is more then 10, you are jupming forvard and skipping adding higher bytes, then add-ing 6, etc. etc.
it would be better to do something like this:
| 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 xor ah,ah int 16h mov bl,al 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 ; prepare numbers
and cx,0F0Fh and bx,0F0Fh ; add parts
add bh,ch add bl,cl
; lower to higher part carry cmp bl,10 jb label1 sub bl,10 inc bh
label1:
; higher part correction an print leading "1" if need
cmp bh,10 jb label2 sub bh,10 mov dl,"1" mov ah,2 int 21h label2: or bx, 3030h mov dl,bh mov ah,2 int 21h
mov dl,bl mov ah,2 int 21h
xor ah,ah int 16h
int 20h
message: db 13,10,"enter 2 digit numbers: $" result: db 13,10, "sum: $" |
of course, it is just "academic" way to understand asm basic things
|
| |
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
|
|
|