WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
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
Quote Post


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

PMEmail Poster
Top
shoorick
Quote Post


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
PMEmail PosterUsers Website
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google