Dynamic Profile Codes
Would you like to react to this message? Create an account in a few clicks or log in to continue.

ASSMBLY Languages

Go down

ASSMBLY Languages Empty ASSMBLY Languages

Post by vampscalling Thu Nov 19, 2009 9:19 pm

include macro.txt

.model small
.stack
.data
byteVAL dw 0
temp dw 0

num1 dw ?
num2 dw ?

str1 db 'Enter 1st number: $'
str2 db 'Enter 2nd number: $'
str3 db 'Sum: $'
str4 db 'Difference: -$'
cont db "Try Again? [y/n] : $"


.code


start7:
act7 proc far
initz
public act7
clrscr
clear 4eh,4,12,15,45;bh,ch,cl,dh,dl
gotoxy 5,15

printf str1
call readInt
mov ax,byteVAL
mov num1,ax


gotoxy 7,15
printf str2

call readInt
mov ax,byteVAL
mov num2,ax


mov ax,num1
mov bx,num2

cmp ax,bx
jae greater
jmp notgreater

sugod7:
jmp start7


greater:

add ax,bx
mov byteVAL,ax
jmp printsum



notgreater:

sub bx,ax
mov byteVAL,bx
jmp printdif



printsum:

gotoxy 9,15
printf str3
mov ax,byteVAL
call writeInt
exit

printdif:

gotoxy 9,15
printf str4
mov ax,byteVAL
call writeInt





mov ah,01
int 21h

ret

;start endp

;Procedure that reads 3-digit number and converts its ASCII code to decimal.

readInt proc near
push ax
push bx
push cx
push dx

mov bx,10
mov temp,0
mov byteVal,0

mov cx,3

input:
mov ah,1
int 21h

cmp al,30h
jb invalid
cmp al,39h
ja invalid
jmp convert



invalid:
mov ah,2
mov dl,8
int 21h
mov dl,20h
int 21h
mov dl,8
int 21h
jmp input


start7a:
jmp sugod7

convert:
and ax,0fh
mov temp,ax
mov ax,byteVal
mul bx
add ax,temp
mov byteVal,ax
xor ax,ax
loop input

askagain:

mov ah,7
int 21h

cmp al,13
jne askagain

pop dx
pop cx
pop bx
pop ax

ret
readInt endp


;Procedure that displays n-digit integer in DX:AX

writeInt proc near
push bx
push cx
push dx

mov bx,10
mov cx,0

; integer broken down to digits
again:

xor dx,dx
div bx
push dx
inc cx
or ax,ax
jnz again

display:

pop dx
mov ah,2
add dl,30h
int 21h
loop display

pop dx
pop cx
pop bx

gotoxy 13,15
printf cont
mov ah,01
int 21h

cmp al,'y'
jne bm7
jmp start7a

bm7:
call main

mov ah,01
int 21h

mov ah,01
int 21h


ret

writeInt endp
act7 endp
end
vampscalling
vampscalling
DPC Member

Male
Posts : 31
Age : 32
Joined date : 2009-11-19
Location : Cebu City
Cash : 26269

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum