Chapter 4 experiment 8 of Wang Shuang's assembly language analyzes a strange program

Source: Internet
Author: User

Q:Code,ProgramWhy can it end normally?

 
Assume Cs: codesgcodesg segment mov ax, 4c00h int 21 hstart: mov ax, 0 s: NOP mov Di, offset s mov Si, offset S2 mov ax, CS: [Si] mov Cs: [di], ax S0: JMP short s S1: mov ax, 0 int 21 h mov ax, 0s2: JMP short S1 nopcodesg endsend start

 

After the s part is executed, the s part is rewritten:
JMP S-8
MoV Di, offset s
MoV Si, offset S2
MoV ax, CS: [Si]
MoV Cs: [di], ax
Therefore, when JMP short s executes s again, it will jump to the Cs: 0000 location, that is
MoV ax, 4c00h
Int 21
So it will end normally.

Knowledge point: the transfer instruction is converted to a relative offset address during compilation. Here, ebf6 is the reverse jump of 8 bytes from S2 to S1.
The same command code, ebf6, that indicates redirection
S2:
JMP short S1
NOP
JMP short S1
In
S:
JMP 0000
MoV Di, offset s
MoV Si, offset S2
MoV ax, CS: [Si]
MoV Cs: [di], ax
JMP 0000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.