Language learning Notes (v) BX and loop instructions

Source: Internet
Author: User
5.1
[BX]
and [0] Similar
[0] Indicates the offset address length, the segment address is default in BS,
However [0] in debug is not the same as in ASM, [0] in ASM after ML will become the value of 0
To solve MOV ax,[1] after AXM compiled into MOV ax,1; can be written mov ax,ds:[1]
Four kinds: mov Al,[0];mov al,ds:[0];mov Al,[bx];mov DS:[BX]

Loop: Related to Loops
(ax) =0010h; use () to indicate that the content in Ax is
2000:1000 of the content is 0010: (21000H) =0010h
MOV ax,[2] is described as: (AX) = ((ds) *16+2);
Push Ax can describe:
(sp) = (sp)-2
((ss) *16+ (sp)) = (AX)
Pop ax
(AX) = ((ss) *16+ (SP))
(sp) = (sp) +2

The Convention conforms to the Idata expression constant
MOV Ax,[idata]
mov ax,[bx] i.e.: (AX) = ((DS) *16+ (BX))

INC BX Inc (BX) has increased its own +1

5.2 Loop Command
CX default is the size of the storage program;
The loop operation takes two instructions:
(CX) = (CX)-1
Determines the value in CX, if not 0, jumps to the label and executes if 0
2^n Second Party:
Assume Cs:code
Code segment
Start:mov ax,2
MOV cx,11
S:add Ax,ax
Loop s

MOV ax,4c00h
int 21h
Code ends
End
Three points:
CX Storage cycles (CX values are best placed in front of the label line)
The label address of the loop instruction should be placed in front
The program code to be executed is written between the label and the loop

Implement FFFF:0006 unit to AX assignment
(AH) =0, (AL) = (ffff6h)
MOV Ax,0ffffh (note that because the assembly source program, data is not allowed to start with a letter, so add 0)

Debug introduces the G command and the P command to solve the cyclic debugging problem:
If the Loop command is in 0012;
G 0014 (offset address); Indicates the code that jumps to 0014 at the completion of the loop;
p; means to complete the loop between, jump to the end of the code


Combined application of 5.5loop and [BX]
For the problem of storage of computing problems, we must first consider whether the storage range will be exceeded;
The data in the memory unit is 8 bits and cannot be added directly to the 16-bit.
In multiple loops, if only the offset address changes, you can introduce a new BX or other general-purpose registers, to do the accumulation


5.7 A safe space
It is dangerous to rewrite memory space at will.
0:200H~0:2FFH is the default security space
Copy, meta-unit ffff:x and target unit 0:200H~0:2FFH
First, the 0:200~02FF is represented as: 0020:0~002f:f
So that the offset address is represented by a variable.
S:mov AX,0FFFFH
MOV Ds,ax
MOV DL,[BX]
MOV ax,0020h
MOV Ds,ax
mov [BX],DL
Inc BX
Loop s
Because two data is a different segment, the DS is set two times per cycle
You can borrow ES to put Ds,ax es,ax out of the loop.

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.