Chapter IX checkpoint

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:IPfirst point of the program, as long as [bx + 1]the word units (because it is a word ptr) holds the value 0 to, so databefore in three bytes 0 to save.

This question is to help me solve a cognitive error:
had previously been thought, the IPdirect 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:

  1. 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
  1. The stack, the data, which codes assigned to the respective segments, and then by a command endsetting the first line of code to be executed at this time CSand the IPpoint 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 to codethe first line of code segments as datasegments and codesegment spaced 64K (i.e. FFFF), endinstruction has cssegment registers code, can be no worries the IP is set to 0 It points to codea 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

Checkpoint 9.2

A:

  1. mov cl, [bx]
  2. mov ch, 0
  3. jcxz ok
  4. 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

Experiment 8

A:

Program analysis:

  1. end start, started from the start label
  2. The first two instructions are NOPempty instruction to skip
  3. mov di, offset sDi set to s, i.e., to save
  4. mov si, offset s2Si set to s2, i.e., data source
  5. mov ax, cs:[si]Save two bytes s2 to the ax
  6. mov cs:[di], axThe ax is set to hold ground
  7. jmp short sJump to the s
  8. s is stored at an address of s2 jmp short s1, mov ax, 0it occupies 3 bytes, int 21h2 bytes, the total of 8 bytes of s1; jmp short s12 bytes, a NOP occupies 1 byte, the jmp short s1offset should be -10 ;
    • s stored at jmp short s1occupies two bytes
    • s at the top mov ax, 0occupies three bytes
    • s at the top int 21hoccupies two bytes
    • s at the top mov ax, 4c00hoccupies three bytes
    Therefore, the implementation of the s jmp short s1, the first line of code back to themov ax, 4c00h
  9. Program normally ends

Guess you like

Origin www.cnblogs.com/codeleven/p/10963576.html