Quantcast
Channel: x86 Assembly - Programmers Heaven
Viewing all articles
Browse latest Browse all 152

adding two numbers with tasm

$
0
0
have I gone too far with this program? I am doing something horribly wrong. I need to add two numbers, and have the answer displayed.
We are tasked with writing a a recursive program, adding two base-10 numbers (from 1-8), and displaying the answer. The way this is written, it must prompt you for the base-10 numbers. Here is what i have put together thus far, and I am sure it is a far cry from what it should be. Could anybody help me? Thanks

P.S., if there is an easier way of going about this (using turbo assembler) please let me know.

;;program add (a sub-procedure)
;;Stephen Madden

.model small
.stack 100h
.data
Message DB 'Enter a base-10 numeric digit: $'
return DB, 13, 10, '$'
.code
Addup proc

mov ax, @data
mov ds, ax; Initialize DS

mov DX,offset Message
mov ah, 9h
int 21h

mov ah, 1
int 21h; puts character in al

sub al, 30h
mov bl, al

mov dx,offset return
mov ah, 9h
int 21h; fist do carriage return/line feed
mov dx,offset message
int 21h; displays message (ah is still 9)
mov ah, 1; get character input
int 21h; puts character in al

;convert to number, store in al
sub al, 30h

;add the two numbers, result in bl
add bl, al
;if using td, observe register bl

cmp bl, 10
jl outdigit
mov ah, 2
mov dl, bl
int 21h; output the leading '1'
outdigit:

;return to DOS (by hand)
mov ah, 4ch
int 21h


Addup endp
end Addup


Viewing all articles
Browse latest Browse all 152

Trending Articles