Tải bản đầy đủ (.pdf) (10 trang)

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

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (73.01 KB, 10 trang )

<span class='text_page_counter'>(1)</span><div class='page_container' data-page=1>

<b>CSC 221</b>



<b>Computer Organization and Assembly </b>


<b>Language</b>



<b>Lecture 11: </b>



</div>
<span class='text_page_counter'>(2)</span><div class='page_container' data-page=2>

<b>Lecture 10: Review</b>



Data Transfer Instructions



Operand Types



Instruction Operand Notation



Direct Memory Operands



MOV Instruction



Zero & Sign Extension



XCHG Instruction



</div>
<span class='text_page_counter'>(3)</span><div class='page_container' data-page=3>

<b>Lecture 10: Review</b>



ADD and SUB Instructions and how they affect FLAGS


(

<i>cont.</i>

)



<b>mov ax,00FFh</b>



<b>add ax,1</b> <b>; AX= SF= ZF= CF=</b>


<b>sub ax,1</b> <b>; AX= SF= ZF= CF=</b>


<b>add al,1</b> <b>; AL= SF= ZF= CF=</b>


<b>mov bh,6Ch</b>


<b>add bh,95h</b> <b>; BH= SF= ZF= CF=</b>


<b>mov al,2</b>


<b>sub al,3</b> <b>; AL= SF= ZF= CF=</b>


<b>0100h 0 0 0</b>
<b>00FFh 0 0 0</b>
<b>00h 0 1 1</b>
<b>01h 0 0 1</b>


</div>
<span class='text_page_counter'>(4)</span><div class='page_container' data-page=4>

<b>Lecture Outline</b>



Data-Related Operators and Directives



– OFFSET, PTR, TYPE, etc. Operators


Indirect Addressing in Assembly



– Indirect Operands
– Array Sum Example
– Indexed Operands


– Pointers


Index Scaling



</div>
<span class='text_page_counter'>(5)</span><div class='page_container' data-page=5>

<b>Data-Related Operators and Directives</b>



• OFFSET Operator
• PTR Operator


• TYPE Operator


• LENGTHOF Operator
• SIZEOF Operator


</div>
<span class='text_page_counter'>(6)</span><div class='page_container' data-page=6>

<b>OFFSET Operator</b>



• 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:


</div>
<span class='text_page_counter'>(7)</span><div class='page_container' data-page=7>

<b>OFFSET Examples</b>




<b>.data</b>


<b>bVal BYTE ?</b>
<b>wVal WORD ?</b>
<b>dVal DWORD ?</b>
<b>dVal2 DWORD ?</b>
<b>.code</b>


<b>mov esi,OFFSET bVal </b> <b>; ESI = 00404000</b>


<b>mov esi,OFFSET wVal </b> <b>; ESI = 00404001</b>


<b>mov esi,OFFSET dVal </b> <b>; ESI = 00404003</b>


<b>mov esi,OFFSET dVal2</b> <b>; ESI = 00404007</b>


</div>
<span class='text_page_counter'>(8)</span><div class='page_container' data-page=8>

<b>Relating to C/C++</b>



<b>; C++ version:</b>
<b>char array[100];</b>
<b>char * p = array;</b>


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


<b>.data</b>


<b>array BYTE 100 DUP(?)</b>
<b>.code</b>



</div>
<span class='text_page_counter'>(9)</span><div class='page_container' data-page=9>

<b>PTR Operator</b>



<b>.data</b>


<b>myDouble DWORD 12345678h</b>
<b>.code</b>


<b>mov ax,myDouble </b> <b>; error – why?</b>


<b>mov ax,WORD PTR myDouble</b> <b>; loads 5678h</b>


<b>mov WORD PTR myDouble,4321h</b> <b>; saves 4321h</b>


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


</div>
<span class='text_page_counter'>(10)</span><div class='page_container' data-page=10>

<b>Little Endian Order</b>



• 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 + 1
myDouble + 2
myDouble + 3


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


</div>

<!--links-->

×