Chapter 3 of Wang Shuang's compilation

Source: Internet
Author: User

// 2010-06-20 22:54:39

Chapter 3 memory access to registers

3.1 ~ Conclusion 3.5
1. When words are stored in memory, they must be stored in two consecutive address memory units. The low byte of words is stored in the low address unit, and the high byte is stored in the high address unit.
And high, low, and low
2. Use the mov command to access the memory unit. Only the offset address of the unit can be given in the mov command. At this time, the segment address is in the DS register by default.
3. [address] indicates a memory unit whose offset address is address.
4. When the font data is transmitted between memory and registers, the high address unit and the high 8 bit register, the low address unit and the low 8 bit register correspond.
5. mov and add sub are commands with two operation objects. JMP is a command with an operation object.
Detection site 3.1
1. In debug, Run "D 0: 0 1f" to view the memory. The result is as follows.
70 80 F0 30 EF 60 30 E2-00 80 80 12 66 20 22 60
2017:0010 62 26 E6 D6 CC 2E 3C 3b-ab Ba 00 00 26 06 66 88
Before the following program is executed, Ax = 0, BX = 0, and write the values in the relevant registers after each assembly instruction is executed.
MoV ax, 1
MoV ds, ax
MoV ax, [0000] AX = 2662 // understand why the address is the same at and for a long time
MoV BX, [0001] BX = e626
MoV ax, bx ax = e626
MoV ax, [0000] AX = 2662

MoV BX, [0002] BX = d6e6
Add ax, bx ax = fd48

Add ax, [0004] AX = 2c14
MoV ax, 0 AX = 0
MoV Al, [0002] AX = 00e6

MoV BX, 0 BX = 0
MoV BL, [000c] BX = 0026

Add Al, bl ax = 000c

2. The memory usage is 3.6.
Initial values of each register: cs = 2000 h, IP = 0, DS = 1000 h, Ax = 0, BX = 0;
1. Write the sequence of commands executed by the CPU (written using assembly commands ).

MoV ax, 6622 H
JMP 0ff0: 0100; adjusted to 10000
MoV ax, 2000 h
MoV ds, ax
MoV ax, [0008]
MoV ax, [0002]; MoV BX, ax this command is not executed

2. Write the value in CS, IP address, and related registers after the CPU executes each instruction.

MoV ax, 6622 h after execution
Cs = 2000 h, IP = 3, Ax = 6622, DS = 1000 h, BX = 0

JMP 0ff0: 0100; after being transferred to 10000 for execution
Cs = 0ff0h, IP = 0100, DS = 1000, Ax = 6622 H, BX = 0

MoV ax, 2000 h after execution

Cs = 0ff0h, IP = 0103, DS = 1000, Ax = 2000 h, BX = 0

MoV ds, after ax execution
Cs = 0ff0h, IP = 0105, DS = 2000 h, Ax = 2000 h, BX = 0
MoV ax, [0008] After execution
Cs = 0ff0h, IP = 0108, DS = 2000 h, Ax = c389, BX = 0

MoV ax, [0002] After execution
Cs = 0ff0h, IP address = 010b, DS = 2000 h, Ax = ea66, BX = 0

3. Try again: is there a difference between data and programs? How do I determine the information in the memory, data, and programs?
Format: both are saved in binary format.
CS: IP to determine the code segment, DS + offset address to determine the Data Segment

 

Stack Overview

The maximum change range of stack top is 0 ~ FFH 8-bit, 0 ~ Ffffh 16-bit, 0 ~ Ffffffffh 32-bit,

0 ~ FFFF ffffh 64

1. Store the segment address and offset address at the top of the stack in the SS and SP;
Provides inbound and outbound stack commands. They access the memory according to the address indicated by the SS: sp.

Unit.

2, push command execution steps: 1, SP = SP-2; 2, sent to the SS: SP pointing to the word UNIT

Data.
3. Execution steps of pop commands: 1. read data from the cell pointed to by SS: sp; 2,

SP = SP + 2.
4. At any time, the SS: SP points to the top element of the stack.
5. The 8086cpu only records the top of the stack. We need to manage the size of the stack space.
6. When stack is used to store the content of registers that need to be restored after the stack is saved, the order of register output stacks must be

The stack order is the opposite.
7. Push and pop are essentially memory-based commands, so pay attention to their flexible application.

Detection site 3.2
1. Complete the following program so that it can ~ 8 characters in 1000fh and copied in reverse order

20000h ~ In 2000fh.
The meaning of reverse replication IS 3.17 (the data in the memory in the figure is assumed ).
MoV ax, 1000 h
MoV ds, ax

MoV BX, 2000 h
MoV SS, BX
MoV sp, 10 h

Push [0]
Push [2]
Push [4]
Push [6]
Push [8]
Push [A]
Push [c]
Push [E]

2. Complete the following program so that it can ~ 8 characters in 1000fh and copied in reverse order

20000h ~ Medium 2000fh
MoV ax, 2000 h
MoV ds, ax

MoV BX, 1000 h
MoV SS, BX
MoV sp, 0

Pop [E]
Pop [c]
Pop [A]
Pop [8]
Pop [6]
Pop [4]
Pop [2]
Pop [0]

Experiment 2 programming with machine instructions and assembly instructions

1. Use debug to write the above program segment to the memory for execution, and run it according to the actual operation after the command is executed.

Fill in the blanks.
MoV ax, FFFF
MoV ds, ax

MoV ax, 2200
MoV SS, ax

MoV SP 0100

MoV ax, [0]; AX = 2200
Add ax, [2]; AX = 5bea
MoV BX, [4]; BX = 0000
Add Bx, [6]; BX = 30f0

Push ax; SP = 0100
Push BX; SP = 00fe
Pop ax; SP = 00fc
Pop BX; SP = 00fe
Push [4]; SP = 0100
Push [6]; SP = 00fe

 

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.