Assembly language - [bx], and instructions and a plurality of loop segments

Description 5.1 [BX] and memory unit

To complete the description of a memory cell requires two types of information:

  • Memory address means:
    • Can be [0] indicates a memory cell, the offset address 0 represents a unit, in the default segment address ds in;
    • The same can also be used [bx] denotes a memory cell, which is offset in bx ; and
  • The length of the memory cell (type):
    • The contents of a memory unit into AX , on the length of this memory cell is 2 bytes (word unit), a word is stored;
    • The contents of a memory unit into Al , on the length of this memory cell is 1 byte (byte unit), a store byte;

5.2 Loop instruction

loop instruction and cx cooperate to achieve circulatory function, cx number of cycles stored.
loop instruction format is: loop label , the CPU performs loop when the instruction to perform two operations

  • (cx)=(cx)- 1
  • Analyzing cx values, not zero then go to program execution at label, if zero is performed downward.
    Its framework:
    mov cx, 循环次数
s:
    循环执行的程序段
    loop s

5.3 comprising a plurality of program segments

In the mode 8086, if space limitations data, stack and code needs more than 64KB, can not be placed in a segment, the data should be, the stack and the corresponding code in the code segment , a stack segment , the data segment ;
example:

assume cs:code,ds:data,ss:stack
data segment
    dw 0001h,0002h,0003h,0004h,0005h,0006h,0007h,0008h  ;dw定义字形数据
data ends
stack segment
    db 0,0,0,0,0,0,0,0      ;定义字节型数据
stack ends
code segment
start: 
    mov ax,data     ;把数据段地址放入ax
    mov ds,ax
    mov ax,stack        ;把栈段地址放入ax
    mov ss,ax
    mov sp,18h  ;设置栈顶指向18h ,18h = 数据段8个字+栈段8个字节共24字节换成16进制。
    mov ax,4c00h
    int 21h
code ends
end start       ;end除了通知编译器程序结束外,还可以通知编译器程序的入口在什么地方。在这指明了程序的入口在标号 start 处。

Guess you like

Origin www.cnblogs.com/chengmf/p/12454670.html