.model small
.stack 256h
.data
msg db ' DUMAGUETE DAILY NEWS ',10,13,'$'
msg1 db ' Want to buy a newspaper:(y/n)? $'
msg2 db 10,13,' Please enter amount of money: $'
msg3 db 10,13,' !!Choose kind of news paper!! Total$'
msg4 db 10,13,' PDI - P20.00 :','$'
msg5 db 10,13,' PS - P20.00 :','$'
msg6 db 10,13,' NC - P10.00 :','$'
msg7 db 10,13,' Y O U R C H A N G E: ','$'
msg8 db 10,13,' ---------',10,13,'$'
msg9 db ' ','$'
num0 dw ?
num1 dw ?
num2 dw ?
num3 dw ?
num4 dw ?
num5 dw ?
num6 dw ?
num7 dw ?
.code
start:
mov ax,@data
mov ds,ax
mov ax,offset msg
call put_string
mov ax,offset msg1
call put_string
call get_char
mov bl,al
cmp bl,'y'
je next
cmp bl,'Y'
je next
cmp bl,'n'
call exit
cmp bl,'N'
call exit
next:
mov ax,offset msg3
call put_string
mov ax,offset msg4
call put_string
mov ax,offset msg5
call put_string
mov ax,offset msg6
call put_string
;--------PDI---------
mov dx,052Ah
mov ah,02h
mov bh,00h
int 10h
call get_num
mov num1, ax
mov dx,0539h
mov ah,02h
mov bh,00h
int 10h
call get_num
mov num2, ax
;---------PS-------
mov dx,062Ah
mov ah,02h
mov bh,00h
int 10h
call get_num
mov num3,ax
mov dx,0639h
mov ah,02h
mov bh,00h
int 10h
call get_num
mov num4,ax
;--------NC---------
mov dx,072Ah
mov ah,02h
mov bh,00h
int 10h
call get_num
mov num5, ax
mov dx,0739h
mov ah,02h
mov bh,00h
int 10h
call get_num
mov num6,ax
;-------total-----------
mov dx,073Bh
mov ah,02h
mov bh,00h
int 10h
mov ax, offset msg8
call put_string
mov ax, offset msg9
call put_string
mov ax, num2
add ax, num4
add ax, num6
call put_num
mov num7, ax
;----- money input--------
mov ax, offset msg2
call put_string
call get_num
mov num0, ax
mov ax, offset msg7
call put_string
mov bx, num7
sub bx, num0
mov ax, bx
call put_num
jmp exit
exit:
mov ah,4ch
int 21h
put_string:
mov dx, ax
mov ah, 9h
int 21h
ret
get_char:
mov ah, 1h
int 21h
ret
put_char:
mov dl,al
mov ah, 2h
int 21h
ret
get_num:
push bx
push cx
push dx
mov dx, 1
mov bx, 0
mov cx, 0
call get_char
cmp al, ' '
jne newline
mov dx, -1
call get_char
newline:
push dx
cmp al, 13
je fin_read
sub al, '0'
mov bl, al
mov ax, 10
mul cx
mov cx, ax
add cx, bx
call get_char
read_loop:
cmp al, 13
je fin_read
sub al, '0'
mov bl, al
mov ax, 10
mul cx
mov cx, ax
add cx, bx
call get_char
jmp read_loop
fin_read:
mov ax, cx
pop dx
cmp dx, 1
je fin_getn
neg ax
fin_getn:
pop dx
pop cx
pop bx
ret
put_num:
push bx
push cx
push dx
mov dx, 0
push dx
mov cx,10
cmp ax, 0
jge calc_digits
neg ax
push ax
mov al, ' '
call put_char
pop ax
calc_digits:
div cx
add dx, '0'
push dx
mov dx, 0
cmp ax, 0
jne calc_digits
display_loop:
pop ax
cmp ax, 0
je end_display_loop
call put_char
jmp display_loop
end_display_loop:
pop dx
pop cx
pop bx
ret
end start
No comments:
Post a Comment