Assembly Language Programming notes

Source: Internet
Author: User

Compilation Study NOTE 1

Study Bibliography "assembly language" second Edition engineering machinery Industry Press


Suppose x=4,y=5,z= ((x+y) *8-x)/2. Write a assembler program to implement the formula calculation:

DATAS SEGMENT
    x DW 4  ; define x as a word cell with a value of 4
    Y DW 5
    Z DW?  ; Define Z as empty cell
DATAS ENDS

STACKS SEGMENT
    ; Enter stack segment code
STACKS ENDS
    CODES SEGMENT assume Cs:codes,ds :D atas,ss:stacks
START:
    mov ax,datas
    mov ds,ax
   
    mov bx,x
    mov ax,y
    ADD ax,bx  ; addition
    MOV cl,3
    SAL ax,cl   ; arithmetic left 3 bits, equivalent to multiplying by 8
    SUB ax,x
    SAR ax,1     ; arithmetical right shift one bit, equivalent to dividing by 2
    mov z,ax
    mov z,ax
    
    mov Ah,4ch
    INT 21H
CODES ENDS
    END START

Meaning:

1) x, Y, z these three variables should be considered as storage units, symbolic addresses

2) Describe the relationship between the segment register and the segment name using the assume pseudo-directive

3) START represents the offset address of the unit where the assembly instruction MOV Ax,datas is located, and the logical instruction of the instruction is Cs:start

4) INT 21H is the DOS interrupt call instruction; the function of 4CH is to end the program and return DOS


(1) Disassembly instruction U

The first instruction logical address 0b52:0000, that is, is specified from the code snippet NO. 0 Unit start storage;

If the program is longer and one screen does not appear, you should press the U instruction until the last instruction of the program appears (

MOV ah,4ch

INT 21H

(2) Execute program command g

The G command can execute the instruction continuously until the breakpoint is given.

AX=4C22, of which ah=4c, should be caused by movah,4ch;

(3) View storage Unit Command D

View storage Unit Commands D

X, y, z are defined in the program are the word units, so the two bytes as a word unit;

So, 0004 in unit 1th and No. 0 is the value of X, and 2nd in unit 3rd and 0005 is the value of Y, and

The value of z is 0022 in unit 5th and unit 4th;

(4) exit the debug command Q

After executing the q command, exit debug to return DOS;


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.