小弟初學匯編多指教!
編譯時出現了jump out of range 2 byte
求大佬救急
assume cs:code
; mov dx,28bH ; mov dx, 283H
; mov al,10000000B ; mov al 001101110B
; out dx, al ; out dx al
; mov dx,288h
; mov al,03h
; out dx, al
data segment
keys db "zxcvbnmasdfghjqwertyu" ;低,中,高音的按鍵
freq db 131,147,165,175,196,220,247 ;低音頻率
welc db 'Welome to Keyboard Piano'
data ends
stack segment
dw 128 dup(0)
stack ends
code segment
;assume cs:code ,ds:data
start:
mov ax, data
mov ds, ax ;初始化資料區
lea dx,welc
mov ah,9
int 21h ; 顯示歡迎陳述句
input:
mov ah, 08h
int 21h ;獲取輸入
cmp al, 0Dh ;判斷輸入的是否是回車符
jz exit ;如果是回車符,則退出
mov cx, 21
lea di, keys
find:
cmp al, [di]
je note ;轉到note
inc di
loop find ;根據key值找到相應地址
jmp input
note:
call getfreq
call sound ;輸出聲音
jmp input
getfreq proc
mov dl, 1 ;記錄頻率倍數
lea bx, keys
sub di, bx
cmp di, 6 ;低音
jna sou
add dl, 1
sub di, 7
cmp di, 6 ;中音
jna sou
add dl, 2
sub di, 7
cmp di, 6
jna sou ;高音
sou:
mov ax, di
lea bx,freq
xlat
mul dl
mov bx, ax
ret
getfreq endp
sound proc
mov dx, 283H
mov al, 00110110B
out dx, al ;寫入控制字
mov dx, 12h
mov ax, 2870h
div bx ;除以指定頻率
out 42h, al
mov al, ah
out 42h, al
mov dx,28bH ;
mov al,10000000B ;
or al, 00000011b
out dx, al ; 打開揚聲器
call delaytime
mov dx, 288H
mov al, 03h
and al, 11111100b
out dx, al ;關閉揚聲器
ret
sound endp
delaytime proc
mov ah, 00h
int 1ah
mov si, dx
delay:
mov ah, 00h
int 1ah
sub dx, si
cmp dx, 3
jna delay
ret
delaytime endp
exit:
mov ax, 4c00h
int 21h
code ends
end start ;set entry point and stop the assembler
uj5u.com熱心網友回復:
簡單的做法,一是用高版本的編譯器,二是把 exit: 及后面的兩句移到 getfreq 子程定義的前面。其它的調整條件轉移邏輯,就稍負責些,且不一定什么場合下都可行。建議用高版本匯編程式,會生產 near 范圍的條件轉移指令。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/205020.html
標籤:匯編語言
