20 สิงหาคม 2554

[Assembly]โปรแกรม บวก ลบ แบบ BCD (ป้อนค่าและแสดงผลได้)


.model small
.data
BALANCE    DB 'Balance: $'
RECEIVE    DB 13,10,'Receive: $'
SELL    DB 13,10,'Sell: $'
REMAIN    DB 13,10,'Remain = '
VRemain      DB '00000',13,10,'$'
VBalance      DB 5,?,'0000'
VReceive      DB 5,?,'0000'
VSell      DB 5,?,'0000'
.code
mov ax,@data
mov ds,ax

mov dx,offset BALANCE       ;input Balance    
mov ah,09h
int 21h
mov dx,offset VBalance
mov ah,0ah
int 21h

mov dx,offset RECEIVE       ;input Receive
mov ah,09h
int 21h
mov dx,offset VReceive
mov ah,0ah
int 21h

mov dx,offset SELL          ;input Sell
mov ah,09h
int 21h
mov dx,offset VSell
mov ah,0ah
int 21h
 
    mov al,VBalance+5           ;digit 4
add al,VReceive+5
aaa
add al,30h
sbb al,VSell+5
aas
mov bl,al

mov al,VBalance+4           ;digit 3
adc al,VReceive+4
aaa
add al,30h
sbb al,VSell+4
aas
mov bh,al

mov al,VBalance+3           ;digit 2
adc al,VReceive+3
aaa
add al,30h
sbb al,VSell+3
aas
mov dl,al

mov al,VBalance+2           ;digit 1
adc al,VReceive+2
aaa
mov dh,al

mov al,30h                  ;digit 0
adc al,VRemain
aaa
add al,30h
mov VRemain,al

mov al,dh                   ;digit 1
add al,30h
sbb al,VSell+2
aas
mov dh,al

mov al,VRemain              ;digit 0
sbb al,0
aas
add al,30h
mov VRemain,al

add bx,3030h                ;keep digit 1-4
mov VRemain+3,bh
mov VRemain+4,bl
add dx,3030h
mov VRemain+1,dh
mov VRemain+2,dl

mov dx,offset REMAIN        ;show digit 0-4
mov ah,09h
int 21h

mov ax,4c00h
int 21h
end

ไม่มีความคิดเห็น:

แสดงความคิดเห็น