Assembly language 1

1. Now create a MASM folder
Insert picture description here
LINK.EXE connection on the E drive
2. Write the code in EX11.ASM
The main frame of the assembly language

DATA SEGMENT

DATA ENDS
CODE SEGMENT
ASSUME   CS:CODE, DS:DATA
START:	MOV  AX, DATA
	MOV  DS,AX
	

	MOV AH, 4CH
	INT 21H
CODE ENDS
END 	START

The semicolon in the assembly language; indicates the comment. The
flag must be remembered:
https://wenku.baidu.com/view/71fe5f06cc17552707220801.html

Insert picture description here

DATA SEGMENT
	BUF1  DB  A8H,9FH,B4H,25H
	BUF2  DB  78H,FFH,D3H,5CH
	BUF3  DB  4  DUP(?) 
DATA ENDS
CODE SEGMENT
ASSUME   CS:CODE, DS:DATA
START:	MOV  AX, DATA
	MOV  DS,AX
	LEA  SI,BUF1
	LEA  DI,BUF2
	MOV BX,OFFSET BUF3
	MOV CX,4
	CLC 	;CF=0,  STC    CF=1//循坏
NEXT:	MOV   AL,[SI]//取字节
	MOV   DL,[DI]//取字节
	ADD AL,DL//相加
	MOV  [BX],AL//存数
	INC   SI//移指针
	INC   DI//移指针
	INC   BX//移指针
	DEC  CX//循环次数减1
	JNZ    NEXT	;ZF=0//循环回去

	MOV AH, 4CH
	INT 21H
CODE ENDS
END 	START

Running code

DATA SEGMENT
	BUF1  DB  A8H,9FH,B4H,25H
	BUF2  DB  78H,FFH,D3H,5CH
	BUF3  DB  4  DUP(?) 
DATA ENDS
CODE SEGMENT
ASSUME   CS:CODE, DS:DATA
START:	MOV  AX, DATA
	MOV  DS,AX
	LEA  SI,BUF1
	LEA  DI,BUF2
	MOV BX,OFFSET BUF3
	MOV CX,4
	CLC 	;CF=0,  STC    CF=1
NEXT:	MOV   AL,[SI]
	MOV   DL,[DI]
	ADD AL,DL
	MOV  [BX],AL
	INC   SI
	INC   DI
	INC   BX
	DEC  CX
	JNZ    NEXT	;ZF=0

	MOV AH, 4CH
	INT 21H
CODE ENDS
END 	START

2. Debug and download

Download
Insert picture description here
DOSBox-assembly environment construction steps
1. Download DOSBox0.74-win32-installer and install it
2. The icon appears on the desktop, click to enter the following interface: (Press alt + Enter to type full screen, then press alt + Enter to return to half screen)
Insert picture description here

3. Bind the MASM directory. The
MASM directory is located at E: \ MASM. There are several basic files for assembler design in this directory: MASM.exe (the assembler program developed by Microsoft, used to put the user-developed assembly language source The program * .asm is assembled into the target file * .obj), LINK.exe (used to connect the target file * .obj to generate * .exe executable file), debug.exe (debug file), EDIT.EXE (full screen text (Editor)
Binding method:
mount c: e: \ wmasm, type C: after pressing Enter, press Enter

The current C drive is associated with E: \ WMASM.
Type the dir command in the current C drive, you can see the files in the E: \ WMASM directory

Insert picture description here
Insert picture description here
The error in the second and third lines of code is because A is regarded as a variable in A8H, and 0 should be added in front.

DATA SEGMENT
	BUF1  DB  0A8H,9FH,0B4H,25H
	BUF2  DB  78H,0FFH,0D3H,5CH
	BUF3  DB  4  DUP(?) 
DATA ENDS

Next step: Connect to the
Insert picture description here
DEBUG command
Debug-R to view and change the contents of the CPU register
Debug-D to view the contents of the memory
Debug-E to rewrite the contents of the memory
Debug-U to translate the machine instructions in the memory into assembly instructions
Debug-T to execute A machine instruction
Debug-A writes a machine instruction in memory in the format of an assembly instruction

Original link: https://blog.csdn.net/qq_36215315/article/details/79893476

Although the instruction ADD in the code is compiled without error, the result is wrong, and ADC should be used.
Insert picture description here
Insert picture description here
Insert picture description here

Published 44 original articles · Likes2 · Visits 540

Guess you like

Origin blog.csdn.net/qq_43699776/article/details/105201555