用彙編實現十六進位數的輸入

來源:互聯網
上載者:User

 從鍵盤輸入兩個四位十六進位數:

                      寫了一個input子程式,輸入一個四位十六進位,調用兩次可實現輸入兩個四位十六進位,輸入的結果第一個存放在num+2開始的字單元,第二個數存放在num 開始的字單元。

 

[code=Assembly]  

data segment
stri db 'input a number :',0ah,0dh,'$'
max db 5
actlen db ?
string db 5 dup(?)
num dw 2 dup(?)
data ends

stack segment
 dw 256h dup(0)
stack ends

code segment
 assume ds:data,ss:stack,cs:code
start:  mov ax,data
 mov ds,ax
 
 call input
 mov ax,num
 mov num+2,ax

 mov dl,0ah   ;換行
 mov ah,2
 int 21h
 call input

 mov ah,4ch
 int 21h

input proc near  ;輸入一個四位十六進位數,0~F之間的四個字元
 push dx
 push ax
 push si
 push cx
 push bx

 mov dx,offset stri  ;顯示字串
 mov ah,9h
 int 21h

 lea dx,max  
 mov ah,0ah
 int 21h  ;調用DOS中斷輸入一個四位十六進位
 
 lea si,string  ;取字串首址
 mov cx,4     
 xor dx,dx 
get: push cx
 mov al,[si]    ;取一個字元
 cmp al,'0'
 jb return
 cmp al,'F'     ;檢查輸入的字元是否在0~F之間
 ja return      ;否,返回
 cmp al,'9'     ;轉換為對應的數字
 jle deci
 sub al,07h
deci: sub al,30h
 cbw
 or  dx,ax
 mov bx,dx
 and bx,0f000h
 jnz nos
 mov cl,4
 shl dx,cl
nos: inc si
 pop cx
 loop get
return: mov num ,dx    ;儲存結果
 pop bx
 pop cx
 pop si
 pop ax
 pop dx
 ret
input endp
code ends
 end start

[/code]

繼續完善。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.