1. Trang chủ
  2. » Trung học cơ sở - phổ thông

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

10 11 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 10
Dung lượng 73,01 KB

Nội dung

Recall that little endian order is used when storing data in memory….[r]

(1)

CSC 221

Computer Organization and Assembly Language

Lecture 11:

(2)

Lecture 10: Review

• Data Transfer Instructions

– Operand Types

– Instruction Operand Notation

– Direct Memory Operands

– MOV Instruction

– Zero & Sign Extension

– XCHG Instruction

(3)

Lecture 10: Review

ADD and SUB Instructions and how they affect FLAGS

(cont.)

mov ax,00FFh

add ax,1 ; AX= SF= ZF= CF=

sub ax,1 ; AX= SF= ZF= CF=

add al,1 ; AL= SF= ZF= CF=

mov bh,6Ch

add bh,95h ; BH= SF= ZF= CF=

mov al,2

sub al,3 ; AL= SF= ZF= CF=

0100h 0 0 00FFh 0 0 00h 1 01h 0 1

(4)

Lecture Outline

• Data-Related Operators and Directives

– OFFSET, PTR, TYPE, etc Operators

• Indirect Addressing in Assembly

– Indirect Operands – Array Sum Example – Indexed Operands – Pointers

• Index Scaling

(5)

Data-Related Operators and Directives

• OFFSET Operator • PTR Operator

• TYPE Operator

• LENGTHOF Operator • SIZEOF Operator

(6)

OFFSET Operator

• OFFSET returns the distance in bytes, of a label from the

beginning of its enclosing segment – Protected mode: 32 bits

– Real mode: 16 bits

offset

myByte data segment:

(7)

OFFSET Examples

.data

bVal BYTE ? wVal WORD ? dVal DWORD ? dVal2 DWORD ? .code

mov esi,OFFSET bVal ; ESI = 00404000

mov esi,OFFSET wVal ; ESI = 00404001

mov esi,OFFSET dVal ; ESI = 00404003

mov esi,OFFSET dVal2 ; ESI = 00404007

(8)

Relating to C/C++

; C++ version: char array[100]; char * p = array;

The value returned by OFFSET is a pointer Compare the following code written for both C++ and assembly language:

.data

array BYTE 100 DUP(?) .code

(9)

PTR Operator

.data

myDouble DWORD 12345678h .code

mov ax,myDouble ; error – why?

mov ax,WORD PTR myDouble ; loads 5678h

mov WORD PTR myDouble,4321h ; saves 4321h

Overrides the default type of a label (variable) Provides the flexibility to access part of a variable

(10)

Little Endian Order

• Little endian order refers to the way Intel stores integers

in memory

• Multi-byte integers are stored in reverse order, with the

least significant byte stored at the lowest address

• For example, the double word 12345678h would be

stored as:

12345678 5678 0000

1234 78 56 34 12 0001 0002 0003 offset doubleword word byte

myDouble myDouble + myDouble + myDouble +

When integers are loaded from memory into registers, the bytes are

Ngày đăng: 01/04/2021, 18:32

w