Compile learning notes for beginners (14th) -- directly address the table

Source: Internet
Author: User

Getting started with crazy summer vacation Study Notes (14th)-direct address table


Reference: chapter 16th of Assembly Language


1. Description unit length label


Common labels: a, B

assume cs:codecode segmenta:db 1,2,3,4,5,6,7,8b:dw 0start:mov si,offset amov di,offset bmov ah,0mov cx,8s:mov al,cs:[si]add cs:[di],axinc siloop smov ax,4c00hint 21hmov ax,4c00hint 21hcode endsend start


Take a closer look at the labels of the following code. The numbers A and B below are not followed by colons. They are labels that can describe the unit length. Also called data label

assume cs:codecode segmenta db 1,2,3,4,5,6,7,8b dw 0start:mov si,offset amov ah,0mov cx,8s:mov al,a[si]add b,axinc siloop smov ax,4c00hint 21hmov ax,4c00hint 21hcode endsend start

We can:

MoV ax, BX is equivalent to mov ax, CS: [8]

MoV B, 2 is equivalent to mov word PTR Cs: [8], 2

Inc B is equivalent to INC word PTR Cs: [8]

MoV Al, a [Si] is equivalent to mov Al, CS: 0 [Si]

MoV Al, a [3] is equivalent to mov Al, CS: 0 [3]


But the following is wrong.

MoV Al, B because B is DW, font

Add B, Al


2. Use data labels in other segments


A common label with a ":" can only be defined in a code segment. Data labels can be used in other segments.


Example: If you want to write DS: B as B directly, you must add Cs: data after assume.

assume cs:code,ds:datadata segmenta db 1,2,3,4,5,6,7,8b dw 0data endscode segmentstart:mov ax,datamov ds,axmov si,offset amov ah,0mov cx,8s:mov al,a[si]add b,axinc siloop smov ax,4c00hint 21hmov ax,4c00hint 21hcode endsend start



3. Direct addressing table


We can create a table and use the table query method to speed up processing.


Example: A hexadecimal number character is displayed on the screen. The character here is used for a table.

Assume Cs: codecode segmentstart: mov Al, 0 ehcall showbytemov ax, 4c00hint 21 hshowbyte: JMP short showtable dB 'hangzhou'; Tables Table show: Push bxpush esmov ah, alshr ah, 1; 4-digit shift to the right, 4-digit high in AH, 4th-digit SHR ah, 1shr ah, 1shr ah, 1and Al, 00001111 bmov BL, ahmov BH, 0mov Ah in Al, table [BX] mov BX, 0b800hmov es, bxmov ES: [160*12 + 40*2], ahmov BL, AlMoV BH, 0mov Al, table [BX] mov ES: [160*12 + 40*2 + 2], alpop ESPOP bxretcode endsend start


We can also store the subprogram address in the direct addressing table to facilitate the calling of different subprograms.






Compile learning notes for beginners (14th) -- directly address the table

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.