Lecture 11 - Addressing Modes in Assembly. In this chapter, the following content will be discussed: How do we represent data in a computer? Computer is a binary digital system, what kinds of data do we need to represent? Unsigned integers, unsigned binary arithmetic,.and other contents. | CSC 221 Computer Organization and Assembly Language Lecture 11: Addressing Modes in Assembly Lecture 10: Review Data Transfer Instructions Operand Types Instruction Operand Notation Direct Memory Operands MOV Instruction Zero & Sign Extension XCHG Instruction Direct-Offset Instructions 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 0 00FFh 0 0 0 00h 0 1 1 01h 0 0 1 FFh 1 0 1 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 JMP and LOOP Instructions Data-Related Operators and Directives OFFSET Operator PTR Operator TYPE Operator LENGTHOF Operator SIZEOF Operator LABEL Directive OFFSET Operator OFFSET returns the distance in bytes, of | CSC 221 Computer Organization and Assembly Language Lecture 11: Addressing Modes in Assembly Lecture 10: Review Data Transfer Instructions Operand Types Instruction Operand Notation Direct Memory Operands MOV Instruction Zero & Sign Extension XCHG Instruction Direct-Offset Instructions 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 0 00FFh 0 0 0 00h 0 1 1 01h 0 0 1 FFh 1 0 1 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 JMP and LOOP Instructions Data-Related Operators and Directives OFFSET Operator PTR Operator TYPE Operator LENGTHOF Operator SIZEOF Operator LABEL Directive 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 The Protected-mode programs we write only have a single segment (we use the flat memory model). 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 Let's assume that the data segment begins at 00404000h: 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 mov esi,OFFSET array ; ESI is p 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. Recall .