"Assembly Language Third Edition" by Wang Shuang ------Reading Notes
6.1 Use data in code snippets
From a specification point of view, the system should allocate memory space for us.
Pseudo assembly instructions (recognized by the compiler)
db : define byte type variable
dw : define word type variable
dd : define double word type variable
program
assume cs:code
code segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h'
start: mov bx,0
mov ax,0
mov cx,8
s:add ax,cs:[bx]
add bx,2
loop s
mov 4c00h
int 21h
code ends
end start
Executable program
It consists of description information and procedures ,
Descriptive information: It is mainly the information obtained by compiling and linking the program to process the relevant pseudo-instructions in the source program
Program: assembly instructions and defined data from the source program;
The role of pseudo-instruction end
In addition to notifying the compiler of the end of the program, end can also notify the compiler where the entry of the program is
Example: end start indicates that the entry of the program is at the label start, and the label start is an address
After compiling and linking, the program entry specified by "end start" is converted into an entry address,
Stored in the description information of the executable file
When the program is loaded into the memory, the loader reads the program’s entry address from the description information of the program’s executable file,
Set CS:IP
After all: we can arrange Framework Program
assume cs:code
code segment
...数据...
start:
...代码...
code ends
end start
6.2 Use the stack in the code segment
Review the knowledge points of the third chapter stack
6.3 Put data, code, and stack into different segments
the reason:
1) Putting it in the same segment makes the program appear chaotic
2) In the 8086 mode, the capacity of a segment cannot be greater than the 64KB program frame:
assume cs:code
data segment
dw 0123h,0456h
data ends
stack segment
dw 0,0,0,0
stack ends
code segment
start: 第一条命令
code ends
end start