Detection point 9.1 (1)
assume cs:code
data segment
____?______
data ends
code segment
start:
mov ax,data
mov ds,ax
mov bx,0
jmp word ptr [bx+1]
code ends
end start
Q: To make the jmp instruction after executing program, CS: IP to point to the first instruction of the program, what data should be defined in the data segment?
A: At this point you want to make the CS:IP
first point of the program, as long as [bx + 1]
the word units (because it is a word ptr) holds the value 0 to, so data
before in three bytes 0 to save.
This question is to help me solve a cognitive error:
had previously been thought, the IP
direct set 0 to be back in the first line of code? Today toss this question when open book and found that there are two writing:
- The data is also written in the code segment inside, that is, stack, data, code written inside a segment, then the first line of code is usually not executable instructions, so I want to jmp back to the first line of code, not directly to the IP is set to 0
assume cs:code
code segment
db 'welcome to masm!'
start:
mov ax,data
mov ds,ax
mov bx,0
jmp word ptr [bx+1]
code ends
end start
- The stack, the data, which codes assigned to the respective segments, and then by a command
end
setting the first line of code to be executed at this timeCS
and theIP
point codes at the reference numeral (i.e., that line start reference example under starting) . At this time, the IP is set to 0 directly, can directly point tocode
the first line of code segments asdata
segments andcode
segment spaced 64K (i.e. FFFF),end
instruction hascs
segment registerscode
, can be no worries the IP is set to 0 It points tocode
a first line segment.
assume cs:code
data segment
db 0, 0, 0
data ends
code segment
mov ax, 0
start:
mov ax,data
mov ds,ax
mov bx,0
jmp word ptr [bx+1]
code ends
end start
Detection point 9.1 (2)
assume cs:code
data segment
dd 12345678H
data ends
code segment
start: mov ax,data
mov ds,ax
mov bx,0
mov [bx], ___①____
mov [bx+2], ___②___
jmp dword ptr ds:[0]
mov ax,4c00H
int 21H
code ends
end start
Q: complement program the cs: ip first instruction to the executable.
A:
①: BX (Anyway, gotta go pass a 0)
②: code | Start label
Analysis: low puts the IP address, put high CS address
Detection point 9.1 (3)
View memory with Debug, results are as follows:
2000:1000 BE 00 06 00 00 00 ......
At this time, CPU executes instructions:
mov ax,2000h
rice, Ax
jmp dword ptr es:[1000h]
Q: After the execution of the program, (CS) = ?, (IP) =?
A:(CS) = 0006,(IP) = 00BE
Checkpoint 9.2
A:
- mov cl, [bx]
- mov ch, 0
- jcxz ok
- inc bx
Checkpoint 9.3
assume cs:code
code segment
start: mov ax,2000h
mov ds,ax
mov bx,0
s:mov cl,[bx]
mov ch,0
________
inc bx
loop s
ok:dec bx
mov dx,bx
mov ax,4c00h
int 21h
code ends
end start
Q: complement programming, using loop instructions, to achieve the first byte to find a value of 0 in the memory segment 2000H, after finding, it is stored in the offset address of dx.
A:
①: CX INC.
Because the loop instruction performs --cx , after cx determines whether the jump is executed to determine whether 0;
Experiment 8
A:
Program analysis:
- end start, started from the start label
- The first two instructions are
NOP
empty instruction to skip mov di, offset s
Di set to s, i.e., to savemov si, offset s2
Si set to s2, i.e., data sourcemov ax, cs:[si]
Save two bytes s2 to the axmov cs:[di], ax
The ax is set to hold groundjmp short s
Jump to the s- s is stored at an address of s2
jmp short s1
,mov ax, 0
it occupies 3 bytes,int 21h
2 bytes, the total of 8 bytes of s1;jmp short s1
2 bytes, a NOP occupies 1 byte, thejmp short s1
offset should be -10 ;- s stored at
jmp short s1
occupies two bytes - s at the top
mov ax, 0
occupies three bytes - s at the top
int 21h
occupies two bytes - s at the top
mov ax, 4c00h
occupies three bytes
jmp short s1
, the first line of code back to themov ax, 4c00h
- s stored at
- Program normally ends