1-1
Implements a simple function call.
Focus on Stack-oriented applications.
RET is called when a call is returned, and a number is followed to indicate the number of bytes of data into the stack during the call.
1-2
Implements code self-migration.
The include statement cannot start with a file because the program starts from the first line during execution. (It may be relocated. It is unknown currently)
The memory addresses marked after the move must be adjusted again.
When short jump or short call is used, the label does not need to be adjusted because the indirect address of the operand here is the difference between the two addresses; when calling a long jump or long call, the operand is the absolute value and needs to be adjusted.
In the indirect addressing of the access stack, only BP can be used for offset.
Do not write anything to CS at any time, or the program will crash.
1-3
Copy the fat and root directories of a floppy disk to the memory.
Current memory usage:
9000: Running --9000: 01ff Boot Code, total length: 512
9000: 0200--9000: 13ff fat content, total length: 1200 h
9000: 1400--9000: 2fff root directory content, total length 1c00h
In the fat2 file system, the first three bytes are the jump command, the last 59 bytes are the disk parameter, then the 448 byte code area, and finally the 0xaa55 boot flag.
The problem is that the compiled code is too long, with only 167 bytes of code segment left.
The next step is to use macro definitions instead of short function calls to further compress the code.
1-4
After changing dispstr to a macro definition, the code is successfully compressed into 22 bytes.
The header file containing macro must start with the file, so the macro definition should be placed in a separate file.
Loop uses a relative offset.
When loop is used, the Cx value is the number of cycles, and there is no plus or minus one offset.
1-5
Current memory usage:
9000: Running --9000: 01ff Boot Code, total length: 512
9000: 0200--9000: 13ff fat content, total length: 1200 h
9000: 1400--9000: 2fff root directory content, total length 1c00h
You can find the loader. com file.
In the fat2 file system, all file names are automatically converted to uppercase.
Method for returning dos in real mode:
% Macro returndos 0; here 0 must be written
MoV ax, 4c00h
Int 21 h
% Endmacro
Next step:
Load loader.com
Then the memory content should be:
9000: Running --9000: 01ff Boot Code, total length: 512
9000: 0200--9000: 13ff fat content
9000: 1400--9000: 2fff root directory content, total length 1c00h
9000: 3000--9000: fc00 loader.com
1-6
Load loader.com
The memory content is:
9000: Running --9000: 01ff Boot Code, total length: 512
9000: 0200--9000: 13ff fat content, total length: 1200 h, that is, 4608 bytes
9000: 1400--9000: 2fff root directory content, total length 1c00h
9000: 3000--9000: fc00 loader.com, total length: 0cc00h, that is, 52224 bytes
Will jump to 9000: 3000
Code address:
Http://d.download.csdn.net/filedown2008/aHR0cDovL2RsMi5jc2RuLm5ldC9kb3duNC8yMDA4MDMzMC8zMDIxMzU0MTgyMi56aXA=! 398454