编写一个简单的程序:将“This is my first ASM program-姓名(汉语拼音各人的姓名)”放在DS=1000H,BX=0000H开始的存储器单元中,然后将该内容搬移到BX=0100H开始的单元中,最后将该字符串通过DOS功能调用显示在屏幕上。
; 声明数据段
data segment
msg db "this is first asm program-ya*******ao$"
db 1000 DUP(0) ; 未初始化数据
ends
; 声明栈段
stack segment
dw 128 dup(0)
ends
; 声明代码段
code segment
start:
mov ax, data ; 将数据段的首地址mov到ds寄存器,需要注意的是不能直接mov ds, data,必须需要通过ax寄存器间接赋值,这个是汇编的知识。
mov ds, ax
mov ax, 1000h
mov es, ax ; 同时将数据段首地址mov到es(extended segment)
mov si, 0
mov di, 0
mov cx, 40 ; 40为字符串msg的长度
copy1: ; 数据从ds复制到1000:0000
mov ax, [si]
mov es:[di], ax ; si和di在没有显式标明段时默认是ds段,这里es:[di]是1000:0000
add si, 2
add di, 2
loop copy1
mov si, 0
mov di, 0100h
mov cx, 40
copy2: ; 将数据复制到1000:0100
mov ax, [si]
mov es:[di], ax ; es:[di]为1000:0100
add si, 2
add di, 2
loop copy2
mov ax, 1000h
mov ds, ax ; 按照题目ds为1000
lea dx, msg ; lea(load effective address,加载有效地址), 将msg的地址存到dx寄存器中,等效于mov dx, offset msg
mov ah, 9
int 21h ; int 21中断,output string at ds:dx
; wait for any key....
mov ah, 1
int 21h
mov ax, 4c00h ; exit to operating system.
int 21h
ends
end start ; set entry point and stop the assembler.
org 100h
; add your code here
mov ax, 1000h
mov dx, ax
mov bx, 0000h
mov [02h], 'T'
mov [04h], 'h'
mov [08h], 'i'
mov [0ah], 's'
mov [0ch], ' '
mov [0eh], 'i'
mov [10h], 's'
mov [12h], ' '
mov [14h], 'm'
mov [16h], 'y'
mov [18h], ' '
mov [1ah], 'f'
mov [1ch], 'i'
mov [1eh], 'r'
mov [20h], 's'
mov [22h], 't'
mov [24h], ' '
mov [26h], 'A'
mov [28h], 'S'
mov [2ah], 'M'
mov [2ch], ' '
mov [2eh], 'p'
mov [30h], 'r'
mov [32h], 'o'
mov [34h], 'g'
mov [36h], 'r'
mov [38h], 'a'
mov [3ah], 'm'
mov [3ch], '-'
mov [3eh], 'y'
mov [40h], 'a'
mov [42h], '*'
mov [44h], '*'
mov [46h], '*'
mov [48h], '*'
mov [4ah], '*'
mov [4ch], '*'
mov [4eh], '*'
mov [50h], 'a'
mov [52h], 'o'
mov cx, 40
mov bx, 0002h
start:
mov ax, [bx]
mov [bx+0100h], ax
add bx, 2
loop start
mov bx, 0102h
mov cx, 40
print:
mov dl, [bx]
mov ah, 02h
int 21h
add bx, 2
loop print
mov ah, 4ch
int 21h
ret