First, you have to download the DOS-BOX program on the Internet.
Download link: DOS-BOX.
Next, you have to download the debug
download link: debug
extraction code: bx0s.
Then, you need to download nodepad ++ as an IDE
download link for writing assembly code : nodepad ++
After the download is complete, you need to create a new folder specifically for putting the assembler. The entire open path of the folder should not have Chinese, you may wish to create a new folder named ASM under the D or E drive
and then Put in the DOSBOX folder and put
all the files in the windows debug folder (the most important ones in the windows debug folder are these three programs: debug.exe, masm.exe, link.exe)
Next, enter DOSBox folder
Click on the yellow exe file, you will see this interface.
Then, before performing any operation, you must first perform the mount operation, that is, enter the mount e e:\asm
first e finger in the small screen. It depends on which virtual disk you want to operate, depending on your mood, 26 letters will do. E: \ ASM refers to the location where you store the debug program. If you put the debug program in another location (you can't have Chinese in the path), you must take the corresponding action.
mount e e:\asm
This sentence can also be placed in the options.bat file so that you don't have to rewrite it every time you open DOSBox.
Then, you can enter DOSBox.exe to test it, first enter e: Enter, then enter debug Enter, and then enter the r command to view the current location of the register.
The r command is used to view the current status of the register. In this console, you You can also use the a command to input assembly instructions one by one
. There is no problem in debugging a short assembly program on the console. When you need to debug a longer assembly code, it is best to write the program code first, then compile, run and debug.
Here, nodepad ++ will be used. First create a new folder in the current ASM folder for the assembly program you want to write, and do not name the folder in Chinese. For example, create a new folder "40".
Of course, when managing your own files, it is best to name them with meaningful English words or phrase abbreviations. The main reason why I did not do this here is. . . Alas, I haven't learned English well, and two lines of tears in programming. . .
Open this folder and create a new file named "40.asm":
(Note that if you want to use your computer more quickly, you should check the file extension!)
Right-click and open it with nodepad ++
. The files in the debug folder are placed in this folder:
then open DOSBox.exe, enter e: Enter (the drive letter you mounted), then use the cd command to enter this folder and press cd 40
Enter to
use masm Command to compile, and press masm 40.asm
Enter three times after compiling.
If there is no error in compiling, use the link command to link to generate an executable file . Enter three times after
entering the exe. Then you can enter debug 40.exe to debug. In debug mode, my most commonly used There are several instructions: -r displays the current register status, which is the above -t single-step execution: -d physical address to view the internal data of the register and -p instruction, when the loop is encountered, the result after the entire loop execution can be displayed , -Q exit command Of course, in addition to debugging, you can also directly enter the program name. Exe after the executable file is generated to run the program, generally just return to the moment The front folder shows that the program runs normally and exits normally: here is a program attached to you, the function is to display the string in the specified color at the specified locationlink 40.obj
;在指定的位置,用指定的颜色,显示一个用0结束的字符串
;参数:(dh)=行号(取值范围0~24),(dl)=列号(取值范围0~79),
;(cl)=颜色,ds:si指向字符串的首地址
;应用举例:在屏幕的8行3列,用绿色显示data段中的字符串
assume cs:code, ds:data
data segment
db 'Welcome to masm!', 0
data ends
code segment
start:
mov dh, 8 ;(dh)=行号(取值范围0~24)
mov dl, 3 ;(dl)=列号(取值范围0~79)
mov cl, 2 ;(cl)=颜色
mov ax, data
mov ds, ax
mov si, 0
call show_str
mov ax, 4c00H
int 21H
show_str:
push cx
push si
mov al, 0A0H ;每行有80*2==160个字节==0A0H个字节
dec dh ;行号在显存中从0开始,所以减1
mul dh ;相当于从第(n-1)*0A0H个Byte单元开始
mov bx, ax ;定位好的位置偏移地址存放在bx里(行)
mov al, 2 ;每个字符占两个字节
mul dl ;定位列,结果ax存放的是定位好的列的位置
sub ax, 2 ;列号在显存中下标从0开始,又因为偶字节存放字符,所以减2
add bx, ax ;此时bx中存放的是行与列号的偏移地址
mov ax, 0B800H ;显存开始的地址
mov es, ax ;es中存放的是显存的第0页(共0--7页)的起始的段地址
mov di, 0 ;di指向显存的偏移地址,确定指向下一个要处理的字符的位置
mov al, cl ;cl是存放颜色的参数,这时候al存放颜色了
mov ch, 0 ;下边cx存放的是每次准备处理的字符
s: mov cl, ds:[si] ;ds:[si]指向“Welcome to masm", 0
jcxz ok ;当cl的值为0的时候,cx == 0,则发生跳转,到ok处结束处理
mov es:[bx+di], cl ;偶地址存放字符
mov es:[bx+di+1], al ;奇地址存放字符的颜色属性
inc si ;指向下个字符
add di, 2 ;指向下个字符
jmp short s ;无条件跳转,jcxz是离开的关键跳转
ok: pop si
pop cx
ret ;显示字符串的子程序【定义结束】
code ends
end start
The results of the program run are as follows:
Attached: The two sample programs used in this article are from the small turtle in station b. If you are interested, you can listen to his class. The lecture is very good and very interesting. Since it was originally a free course, So I shouldn't be violating intellectual property right here. . . Just promote it ...