x86 compilation Notes

Source: Internet
Author: User

① several large registers as well as the usual effects.

Free 16-bit: AX (data segment), BX (offset address), CX (counter), DX (temporary data)

AH (break, carry), AL, bh/l,ch/l,dh/l

Pointer 16 bits: SP,BP

Index 16 bits: SI, DI (both as pointers to offset addresses)

Segment 16 bits: CS, DS, SS, ES

Directives & Signs: Not studied for the time being

[Limit] Offset address register: Bx,si,di

[Limit] counter register: Cx,loop statement detection =dec CX&JNZ

② Common Statements

MOV ax,01//assignment, register as left value

Add AX,BX//Do not carry addition, here carry refers to overflow problem

Since the maximum value of 16 bits in 8086 is 0xFFFF (65535), exceeding this range overflow, the result = True -65536* (carry +1), more than 16 bits of data, non-intelligent carry, need to look at the bytes after double byte, and *65536 restore calculation

So to record the overflow carry, and finally to restore the truth

The four-segment structure of ③ assembler program

SS (stack segment): usually one statement. Stack 64, set stack size 64KB

DS (data segment): Various variables are stored

Storage rule: small-end format. such as 16-bit data 35f3h, starting at offset position 0000, then 0000 of the 8-bit data f3,0001 is 35, the string is not the rule store.

CS (Code snippet): This is where the code is.

ES (additional segment): not yet studied

Several address issues

Logical address = Segment Address: Offset address (16 bits, upper and lower bounds 0/ffff), such as 2,500:0100

Physical Address = Segment Address shift left one (right 0) + offset address (20 bit)

④ Basic variables

EQU Constants

DB single byte, DW double byte, DD four bytes, DQ eight bytes, DT 10 bytes

DB can only be 8/16-bit registers, DW only 16-bit registers.

DD calculation, in 8086 need to cycle shift 2 times, DQ 4 times, DT 5 times

④ Basic Assembler Program

Double-byte summation

. MODEL SMALL. STACK -. DataArray DW23333,23333,23333,23333,23333SUM DW2DUP (0). Codemain PROC far mov AX, @DATA mov ds,ax mov si,offset ARRAY MOV CX, toMOV DX,0MOV BX,0For:add Dx,[si] ADD DI, GenevaADC BX,0DEC CX jnz for mov sum,dx mov SUM+2, BX MOV ah,4ch INT 21HMAIN endpend MAIN
View Code

@ADC usage: When an ADC does addition, it secretly adds the previous accumulated carry value, clearing the CLC

@DW 2 is equivalent to a dd,dup for multivariable initialization

@MOV Ah,4ch&int 21H is the interrupt flag, indicating the end of the program

Double multi-byte loop accumulation

. MODEL SMALL. STACK -. Datacount EQU GenevaDATA1 DD12345678DATA2 DD23456789SUM DD0. Codemain PROC far mov AX, @DATA mov ds,ax mov cx,count mov si,offset DATA1 mov di,offset DATA2 mov bx,off SET SUM For:mov Ax,[si] ADC Ax,[di] MOV [Bx],ax ADD SI, GenevaADD DI, GenevaADD BX, GenevaLOOP for MOV ah,4ch INT 21HMAIN endpend MAIN
View Code

@LOOP usage: self-reducing circulator with CX binding

The @ carry can be transferred to the next calculation without having to be stored separately and multibyte addition.

x86 compilation Notes

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.