datas segment
;此處輸入資料段**
array dw 6789,-
1234,0
,1datas ends
stacks segment
;此處輸入堆疊段**
stacks ends
codes segment
assume cs:codes,ds:datas,ss:stacks
start:
mov ax,datas
mov ds,ax
;此處輸入**段**
mov cx,lengthof array
xor bx,bx
again:mov ax,array[bx]
; call dispsiw;呼叫子程式顯示乙個資料
add bx,type array
call dispcrlf;換行以便顯示下乙個資料
loop again
jmp ex
dispsiw proc near
push ax
push bx
push dx
test ax,ax;判斷是零、正數或負數
jnz dsiw1;不是零,跳轉
mov dl,
'0' mov ah,
2int
21h jmp dsiw5;轉向顯示
dsiw1:jns dsiw2;是正數,跳轉
mov bx,ax
mov dl,
'-';是負數,顯示負號
mov ah,
2int
21h mov ax,bx
neg ax;資料求補(絕對值)
dsiw2:mov bx,
10 push bx;
10壓入堆疊,作為退出標誌
dsiw3:cmp ax,
0;資料(商)為零,轉向儲存
jz dsiw4
xor dx,dx ;擴充套件被除數為dx.ax
div bx ;資料除以10:dx.ax÷10
add dl,
30h ;餘數(0~9)轉換為ascii
push dx ;資料先低位後高位壓入堆疊
jmp dsiw3
dsiw4:pop dx
cmp dl,
10 je dsiw5
mov ah,2;
int21h
jmp dsiw4
dsiw5:pop dx
pop bx
pop ax
retdispsiw endp
dispcrlf proc near
push ax
push dx
mov dl,
0dh ;輸出回車字元
mov ah,
2int
21h mov dl,
0ah ;輸出換行字元
int21h pop dx
pop ax
retdispcrlf endp
ex: mov al,
4ch int
21hcodes ends
end start
;eg504.
asm.model small
.stack
.data
array dw 6789,-
1234,0
,1,-
9876
,32767,-
32768
,5678,-
5678
,9000
count = lengthof array
.code
.startup
mov cx,count
xor bx,bx
again: mov ax,array[bx]
;將ax=入口引數
call dispsiw ;呼叫子程式,顯示乙個資料
add bx,type array
call dispcrlf ;游標回車換行以便顯示下乙個資料
loop again
.exit
dispsiw proc ;顯示有符號十進位制數的通用子程式
push ax ;入口引數:ax=欲顯示的資料(補碼)
push bx
push dx
test ax,ax ;判斷資料是零、正數或負數
jnz dsiw1
mov dl,
'0';是零,顯示「0」後退出
mov ah,
2int
21h jmp dsiw5
dsiw1: jns dsiw2 ;是負數,顯示「-」
mov bx,ax ;ax資料暫存於bx
mov dl,
'-' mov ah,
2int
21h mov ax,bx
neg ax ;資料求補(絕對值)
dsiw2: mov bx,
10 push bx ;
10壓入堆疊,作為退出標誌
dsiw3: cmp ax,
0;資料(商)為零,轉向顯示
jz dsiw4
xor dx,dx ;擴充套件被除數dx.ax
div bx ;資料除以10:dx.ax÷10
add dl,
30h ;餘數(0~9)轉換為ascii碼
push dx ;資料各位先低位後高位壓入堆疊
jmp dsiw3
dsiw4: pop dx ;資料各位先高位後低位彈出堆疊
cmp dl,
10;是結束標誌10,則退出
je dsiw5
mov ah,
2;進行顯示
int21h jmp dsiw4
dsiw5: pop dx
pop bx
pop ax
ret ;子程式返回
dispsiw endp
dispcrlf proc ;回車換行子程式
push ax ;保護暫存器
push dx
mov dl,
0dh ;輸出回車字元
mov ah,
2int
21h mov dl,
0ah ;輸出換行字元
mov ah,
2int
21h pop dx ;恢復暫存器
pop ax
ret ;子程式返回
dispcrlf endp
end
將十六進製制資料轉換成有符號十進位制數
方法一 define read hexadecimal data define hexadecimal row num 32 void main endif int16 translatedata const char buff else temp int32 pow 16.0,i idata te...
彙編實驗 十六進製制轉成十進位制以及十進位制轉十六進製制
十六進製制轉成十進位制 datas segment dbuf dw 3039h 16進製制數3039h為10進製數12345 dval db 5 dup 存放轉換後的資料 dlen dbuf datas ends stacks segment 此處輸入堆疊段 stacks ends codes se...
組合語言 從鍵盤輸入有符號十進位制數的子程式
data segment count 0ah array dw count dup 0 over db read over data ends code segment assume cs code,ds data start mov ax,data mov ds,ax xor ax,ax mov ...