Chapter 2 direct addressing table

Source: Internet
Author: User

Chapter 2 direct addressing table

 

16.1 describes the unit length label

Assume cs: code

Code segment

A db 1, 2, 3, 4, 5, 6, 7, 8

B dw 0

 

Start:

Mov si, 0

Mov cx, 8

S:

Mov al, a [si]

Mov ah, 0

Add B, ax

Inc si

Loop s

 

Mov ax, 4c00h

Int 21 h

 

Code ends

End start

The numbers a and B Used in the code segment are not followed by ":". They are labels that describe both the memory address and unit length. Therefore, in the instruction, it can represent the memory unit in a segment. For example, for the data source of data source B (dw 0) in the preceding program, the number B represents a memory unit. The address is code: 8 and the length is two bytes.

Command: mov ax, B

Equivalent to mov ax, cs: [8];

Command: mov B, 2

Equivalent to mov word ptr cs: [8], 2.

In the future, we will call this labelData labelIt indicates the address and length of the data storage unit. It is different from the address label that only represents an address.

 

16.2 use data labels in other segments

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

For example:

Data segment

A db 1, 2, 3, 4, 5, 6, 7, 8

B dw 0

C dw a, B

Data ends

The two fonts stored at data Mark c are the offset addresses of numbers a and B. Equivalent:

Data segment

A db 1, 2, 3, 4, 5, 6, 7, 8

B dw 0

C dw offset a, offset B

Data ends

For example:

Data segment

A db 1, 2, 3, 4, 5, 6, 7, 8

B dw 0

C dd a, B

Data ends

The two dual-fonts stored at data Mark c are the offset address and segment address of Mark a, and the segment address of the Offset address of Mark B.

Data segment

A db 1, 2, 3, 4, 5, 6, 7, 8

B dw 0

C dw offset a, seg a, offset B, seg B

Data ends

 

16.3 direct addressing table (skipped below)

P306

16.4 direct addressing table of program entry addresses

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

The following Program sets the value of ah before calling. If the value is 0, the screen is cleared. 1 sets the foreground color, 2 sets the background color, and 3 indicates to scroll up a row.

Assume cs: code

Code segment

 

Start:

Setscreen:

Jmp short set

Table dw sub1, sub2, sub3, sub4

 

Set:

Push bx

Cmp ah, 3

Ja sret

Mov bl, ah

Mov bh, 0

Add bx, bx; Calculate the offset of the corresponding subroutine in the table according to the ah function number.

 

Call word ptr table [bx]; call the corresponding function subroutine

Mov ax, 4c00h

Int 21 h

 

Sret: pop bx

Ret

Sub1:

Push bx

Push cx

Push es

Mov bx, 0b800h

Mov es, bx

Mov bx, 0

Mov cx and 2000

 

Sub1s:

Mov byte ptr es: [bx],''

Add bx, 2

Loop sub1s

Pop es

Pop cx

Pop bx

Ret

 

Sub2:

Push bx

Push cx

Push es

 

Mov bx, 0b800h

Mov es, bx

Mov bx, 1

Mov cx and 2000

 

Sub2s:

Add byte ptr es: [bx], 11111000b

Or es: [bx], al

Add bx, 2

Loop sub2s

 

Pop es

Pop cx

Pop bx

Ret

 

Sub3:

Push bx

Push cx

Push es

Mov cl, 4

Shl al, cl

Mov bx, 0b800h

Mov es, bx

Mov bx, 1

Mov cx and 2000

 

Sub3s:

And byte ptr es: [bx], 10001111b

Or es: [bx], al

Add bx, 2

Loop sub3s

Pop es

Pop cx

Pop bx

Ret

 

Sub4:

Push cx

Push si

Push di

Push es

Push ds

 

Mov si, 0b800h

Mov es, si

Mov ds, si

Mov si, 160; ds: si points to row n + 1

Mov di, 0

Cld

Mov cx, 24; 24 rows in total

 

Sub4s:

Push cx

Mov cx and 160

Rep movsb

Pop cx

Loop sub4s

 

Sub4s1:

Mov byte ptr [160*24 + si],''

Add si, 2

Loop sub4s1

Pop ds

Pop es

Pop di

Pop si

Pop cx

Ret

 

Code ends

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.