Direct addressing table (learning Assembly)

Source: Internet
Author: User

1. we can use a label that not only represents the address of the memory unit, but also the length of the memory unit, that is, the Unit at this label, which is a byte unit, it's still a word unit or a dual-word unit. For example

A: Change dB, to a DB

B: Change DW 0 to B DW 0

Use labels without ":". They are labels that describe both the memory address and unit length. This label contains the description of the unit length. Therefore, in the instruction, it can represent the memory unit in a segment.

2. Using this label containing the unit length allows us to access data in the memory in a concise manner. Later, we will call this label a data label, which marks the address and length of the data storage unit. It is different from the address label that only represents an address.

 

Use data labels in other segments

1. In general, we do not define data in the code segment, but define data in other segments. In other segments, we can also use data labels to describe the address and length of the unit for storing data.

2. Note that the address label ":" can only be used in the code segment and cannot be used in other segments.

3. Note: If you want to directly use a data label to access data in a code segment, you need to use the pseudo command assume to associate the segment where the label is located with a segment register. Otherwise, the compiler cannot determine the register where the segment address of the label is during compilation. Of course, this connection is required by the compiler, but it is definitely not to say that we use the assume command to associate the segment register with a specific segment because of the compiler's work needs, the segment register will actually store the segment address. We also need to use instructions in the program to set the segment register.

4. The label can be defined as data. At this time, the compiler regards the address indicated by the label as the data value.

5. the seg operator is used to obtain the segment address of a logo.

 

Attaches a program that uses a direct addressing table to calculate sin (x:

1 Assume Cs: Code 2 code segment 3 Start: 4 mov Al, 60 5 call showsin 6 7 mov ax, 4c00h 8 int 21 H 9 10 showsin: 11 JMP short show 12 Table DW ag0, ag30, ag60, ag90, ag120, ag150, ag18013 ag0 dB '0', 014 ag30 dB '0. 5', 0 15 ag60 db' 0. 866 ', 0 16 ag90 dB '1', 017 ag120 dB '0. 866 ', 0 18 ag150 dB '0. 5', 0 19 ag180 dB '0', 020 21 show: 22 push bx23 push es24 push Si 25 mov BX, 0b800h26 mov es, BX 27 28 mov ah, 0 29 mov BL, 30 30 Div BL 31 mov BL, Al; angle/30 as Table offset, And the quotient Al is placed in BL 32 mov BH, 0 33 Add Bx, BX; because DW occupies 2 bytes, 0-1, 1-2... 34 mov BX, table [BX] 35 mov Si, 160*23 + 40*236 shows: 37 mov ah, CS: [BX] 38 CMP ah, 0; if Ah is 0, it is redirected to showret39 je showret 40 mov ES: [Si], Ah 41 Inc BX 42 Add Si, 243 JMP shows 44 45 showret: 46 pop Si 47 pop es 48 pop BX 49 RET 50 51 52 53 code ends54 end start

 

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.