8086汇编 - 常量和从数组中读取字符

时间:2014-12-23 11:39:49

标签: assembly constants x86-16

我必须编写一个播放音乐笔记的8086汇编程序。

我将音符声明为常量,旋律存储在存储器中,程序读取音符后注释,“X”表示旋律已结束。我的问题是我不知道如何将ASCII码更改为常量值。例如,当程序读取字符'C'时,它应将其常量值(9107)写入AX。

这是我的代码:

dosIntr         equ     21h
retToDos        equ     4ch
noError         equ     0h
;octave
C               =9107 ;1193000/131
D               =8115 ;1193000/147
E               =7230 ;1193000/165
F               =6817 ;1193000/175
G               =6087 ;1193000/196
A               =5423 ;1193000/220
B               =4830 ;1193000/247
W               =1 ;pause 

Progr           segment
                assume  cs:Progr, ds:data, ss:stack
start:          mov     ax,data
                mov     ds,ax
                mov     ax,stack
                mov     ss,ax
                mov     sp,offset stack

                mov     si,0 ;index

play:   ;read char from array   
                mov     bl,notes[si] ;ascii code of note
                cmp     bl,'X' ;check if end
                je      soundEnd

        ;changing ascii to constant
                mov     ax,bx ;copies only ascii code           

        ;8253 send note         
                out     42h,al
                mov     al,ah
                out     42h,al

        ;8255 sound on
                in      al,61h
                or      al,00000011b
                out     61h,al

        ;int15 timer
                xor     dx,dx ;dx = 0
                mov     cx,8 ;half note
                mov     ah,86h
                int     15h

        ;8255 sound off
                in      al,61h
                and     al,11111100b
                out     61h,al

                inc     si ;inc index
                jmp     play


soundEnd:       mov     ah,retToDos
                mov     al,noError
                int     dosIntr
Progr           ends

data            segment
    notes db 'CWDWEWFWGWAWBWX' 
data            ends


stack          segment
                dw    100h dup(0)
top          Label word
stack          ends


end start

0 个答案:

没有答案