data segment para
str1 db ‘one’, ’$’
str2 db ‘Two’, ’$’
str3 db ‘Three’, ’$’
str4 db ‘four’, ’$’
str5 db ‘five’, ’$’
tab dw str1,str2,str3,str4,str5
data ends
ssg segment stack
dw 256 dup(?)
ssg ends
code segment para
assume cs:code,ss:ssg,ds:data
main proc far
mov ax, data
mov ds, ax
mov ah, 1 ;鍵盤輸入
int 21h
call asc2bin
mov bl, al
mov bh, 0
dec bx
shl bx, 1
mov dx, tab[bx]
mov ah, 9
mov ax, 4c00h
Int 21h
main endp
;將ASCII轉換為二進位制數
;入口:AL存放ASCII
;出口:轉換後數值在AL
asc2bin proc
sub al, 30h
cmp al, 9
jbe next
sub al, 7
next: ret
asc2bin endp
end main
data segment para
str1 db ‘one’, ’$’
str2 db ‘Two’, ’$’
str3 db ‘Three’, ’$’
str4 db ‘four’, ’$’
str5 db ‘five’, ’$’
tab dw str1,str2,str3,str4,str5
data ends
ssg segment stack
dw 256 dup(?)
ssg ends
code segment para
assume cs:code,ss:ssg,ds:data
main proc far
mov ax, data
mov ds, ax
mov ah, 1 ;鍵盤輸入
int 21h
call asc2bin
mov bl, al
mov bh, 0
dec bx
shl bx, 1
mov dx, tab[bx]
mov ah, 9
int 21h
mov ax, 4c00h
Int 21h
main endp
;將ASCII轉換為二進位制數
;入口:AL存放ASCII
;出口:轉換後數值在AL
asc2bin proc
sub al, 30h
cmp al, 9
jbe next
sub al, 7
next: ret
asc2bin endp
end main