Getting started with crazy summer vacation Study Notes (5)-a program containing multiple segments
Reference: Chapter 6th of Assembly Language
1. Use Data in the code.
assume cs:codecode segmentdw 0123h,0456h,0789h,0defhmov ax,0mov bx,0mov ax,4c00Hint 21hcode endsend
DW indicates defining the font data and DB indicates defining the byte data.
The above code is compiled and connected, and debug is used.-U Cs: 0 is used to view the assembly code, and mov ax, 0 mov BX, and 0 are not found. The direct operation is not normal. Because the computer does not know the data and the code. If-u Cs: 8, you can see mov ax, 0 mov BX, 0, and so on.
Add the program entry to the correct method.
assume cs:codecode segmentdw 0123h,0456h,0789h,0defhstart:mov ax,0mov bx,0mov ax,4c00Hint 21hcode endsend start
You can change start to another name, as long as the entrance is the same as the end name.
2. Use stacks in code
Example: swap 0123 H and 0456 H
DW 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 applied for stack space
SP 30 h set the starting position of the stack top
assume cs:codecode segmentdw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987hdw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0start:mov ax,csmov ss,axmov sp,30hpush cs:[0]push cs:[2]pop cs:[0]pop cs:[2]mov ax,4c00hint 21hcode endsend start
3. Put data, code, and stack into different segments
Example: store data in data segments in reverse mode
assume cs:code,ds:data,ss:stackdata segmentdw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987hdata endsstack segmentdw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0stack endscode segmentstart:mov ax,datamov ds,axmov ax,stackmov ss,axmov sp,20hmov bx,0mov cx,8s:push [bx]add bx,2loop smov bx,0mov cx,8s0:pop [bx]add bx,2loop s0mov ax,4c00hint 21hcode endsend start
Three segments, data segments, stack segments, and code segments are defined here. DS and SS values must be specified in the Code segment.