Assembly language--------Wang Shuang Chapter 5

[BX]

[BX] and [0] are somewhat similar. [0] means that the offset address is 0 and the segment address is in the DS register, while [BX] is the offset address is the content of the BX register, and the segment address is also in the DS register. For the convenience of the following description, we define a symbol () to represent the contents of a register or a memory unit, such as (ax) to represent the contents of the register ax.
The inc register instruction is to increase the contents of the register by 1, for example, inc bx is to increase the contents of the bx register by 1.

LOOP instruction

The format of the loop instruction is: loop label. When the cpu executes the loop instruction, two operations are required:

  1. (cx) = (cx) -1
  2. If the value in cx is judged to be busy or not zero, it will go to the numbered place to execute the program, and if it is zero, it will execute down.
    What we need to pay attention to is that the number of cycles is stored in the cx register.
    The framework of using cx and loop instructions to realize the loop function is as follows:
         mov cx,循环次数
	s:
		循环执行的程序段
		loop s

The following three rules can be summarized . The address indicated by the label in the loop instruction
to store the number of
loops in cx should be in the previous
program segment to be looped, and should be written in the middle of the label and the loop instruction.

There is another point in the assembly source program that needs special attention:Data cannot start with a letter, Such as ffffh can only be written as 0fffffh.
Tracking the execution of the loop through the debug mode, we find that in the debug mode, the loop mark becomes an address. After judging whether the condition that cx is not 0 is satisfied, if it is satisfied, the value in the ip register is changed to the offset represented by the loop mark Address value, thus completing the jump.
In debug mode, if we want to jump directly to a command to execute it, we can directly use the g offset address to complete it. For example, g 0012 indicates that the command before cs:0012 has been completed. If we think that the logic is correct by observing the loop several times, then we can directly execute the loop instruction at one time through the p command. Or directly use the g offset address method to jump to the assembly instruction after the loop has been executed.

Pay special attention to the different processing of instructions by Debug and assembly compiler masm

We wrote a similar instruction in debug:
mov ax, [0]
This is considered to be the value of offset address 0 being sent to ax in debug, and the masm compiler thinks this is to send the value 0 to the ax register in.
So if you want to achieve a unified effect, you can put the value in the transfer register, for example, first send 0 to bx, and then use mov ax, [bx] to achieve the same effect as debug mode mov ax, [0]. This is more troublesome, we can also change another way, display the address of the expenditure segment and offset address to complete. For example, mov al, ds, [0].

Segment prefix

In the form of mov ax, ss:[0], these appear in the instruction to access the memory unit and are used to explicitly indicate the segment address of the memory unit. "ds:" is called the segment prefix in assembly language.

A safe space

In the 8086 mode, it is very dangerous to write content to a section of memory space at will, because this section of space may store important system data or code. Generally, DOS and other legal programs generally do not use the 0:200~0:2ff space.

Guess you like

Origin blog.csdn.net/weixin_47617598/article/details/115031338