นี้โค้ทอ่ะค่ะ
.model small
.stack
.data
;define variable
Text db "Example",10,13,9,"add 2+2 ",10,9,"sub 2-2 ",10,9,10,"Please input number : ","$"
error db 10,"Condition denied",10,"$"
Ex db 2 dup(?)
check db 1 dup(?)
.code
start:
;Get segment of Text
mov ax,SEG Text
mov ds,ax
;print out to the screen.
mov ah,9h
mov dx,OFFSET Text
int 21h
mov ah,01h
int 21h
mov cl,al
mov ah,01h
int 21h
mov check,al
mov ah,01h
int 21h
mov bl,al
;print =
mov dl,61
mov ah,02h
int 21h
cmp check,43
jz adds
cmp check,45
jz subs
adds:
mov al,cl
adc al,bl
aaa
jmp result
subs:
mov al,cl
sbb al,bl
aaa
jmp result
result:
;print result frist
mov Ex,al
mov Ex+1,ah
;check first number
cmp ah,02
jz resultNext
mov al,Ex+1
add al,46
mov dl,al
mov ah,02h
int 21h
resultNext:
;print result next
mov al,Ex
add al,48
mov dl,al
mov ah,02h
int 21h
;print new line
mov dl,10
mov ah,02h
int 21h
jmp finish
errors:
;print ?
mov dl,63
mov ah,02h
int 21h
;Get segment of Text
mov ax,SEG error
mov ds,ax
;print out to the screen.
mov ah,9h
mov dx,OFFSET error
int 21h
finish:
;Terminate program.
mov ax,4c00h
int 21h
end start
ผลลัพ ออกมา2+2=4
อยากทำเป็น2หลัก10+10=20