1. Trang chủ
  2. » Ngoại Ngữ

Lecture Computer organization and assembly language - Lecture 12: Addressing Modes in Assembly - TRƯỜNG CÁN BỘ QUẢN LÝ GIÁO DỤC THÀNH PHỐ HỒ CHÍ MINH

7 20 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 7
Dung lượng 60,88 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

– You can scale an indirect or indexed operand to the offset of an. array element.[r]

Trang 1

CSC 221

Computer Organization and Assembly

Language

Lecture 12:

Addressing Modes in Assembly

Trang 2

• OFFSET Operator

– OFFSET returns the distance

in bytes, of a label from the

beginning of its enclosing

segment

• PTR Operator

– Overrides the default type of a

label (variable) Provides the

flexibility to access part of a

variable

mov esi,OFFSET bVal ;ESI = 00404000

-.data

array BYTE 100 DUP(?) code

mov esi,OFFSET array ; ESI is p

Data-Related Operators and Directives

.data myBytes BYTE 12h,34h,56h,78h

.code mov ax,WORD PTR [myBytes]

mov ax,WORD PTR [myBytes+2]

mov eax,DWORD PTR myBytes

Trang 3

• TYPE Operator

– The TYPE operator returns the

size, in bytes, of a single

element of a data declaration

• LENGTHOF Operator

– The LENGTHOF operator

counts the number of elements

in a single data declaration

Data-Related Operators and Directives

.data var1 BYTE ? var4 QWORD ?

.code mov eax,TYPE var1 ; 1 mov eax,TYPE var4 ; 8

.data array1 WORD 30 DUP(?),0,0 code

mov ecx,LENGTHOF array1 ;32

Trang 4

• SIZEOF Operator

– The SIZEOF operator returns

a value that is equivalent to

multiplying LENGTHOF by

TYPE

• LABEL Directive

– Assigns an alternate label

name and type to an existing

storage location

– LABEL does not allocate any

storage of its own

– Removes the need for the

PTR operator

Data-Related Operators and Directives

.data array1 WORD 30 DUP(?),0,0

.code mov ecx,SIZEOF array1 ;64

.data dwList LABEL DWORD wordList LABEL WORD intList BYTE 00h,10h,00h,20h code

mov eax,dwList ; 20001000h mov cx,wordList ; 1000h

mov dl,intList ; 00h

Trang 5

• Indirect Operands

Indirect Addressing in Assembly

.data val1 BYTE 10h,20h,30h code

mov esi,OFFSET val1

inc esi

inc esi

.data myCount WORD 0

.code mov esi,OFFSET myCount

inc WORD PTR [esi] ; ok

Trang 6

• Index Operands

– An indexed operand adds a constant to a register to generate an

effective address There are two notational forms:

Indirect Addressing in Assembly

.data arrayW WORD 1000h,2000h,3000h code

mov esi,0 mov ax,[arrayW + esi] ; AX = 1000h mov ax,arrayW[esi] ; alternate format add esi,2

add ax,[arrayW + esi]

………

Trang 7

• Index Scaling

– You can scale an indirect or indexed operand to the offset of an

array element This is done by multiplying the index by the array's TYPE:

Indirect Addressing in Assembly

.data arrayB BYTE 0,1,2,3,4,5 arrayW WORD 0,1,2,3,4,5

.code mov esi,4

………

Ngày đăng: 01/04/2021, 02:30

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w