Download 2_Chapter4_Data transfer

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Assembly Language for IntelBased Computers, 5th Edition
Kip Irvine
Chapter 4: Data Transfers,
Addressing, and Arithmetic
(c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use,
or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.
What's Next





Data Transfer Instructions
Addition and Subtraction
Data-Related Operators and
Directives
Indirect Addressing
JMP and LOOP Instructions
Web site
Examples
2
Addition and Subtraction





INC and DEC Instructions
ADD and SUB Instructions
NEG Instruction
Implementing Arithmetic
Expressions
Flags Affected by Arithmetic




Zero
Sign
Carry
Overflow
Web site
Examples
3
INC and DEC Instructions

Add 1, subtract 1 from destination
operand


operand may be register or memory
INC destination


Logic: destination  destination + 1
DEC destination

Logic: destination  destination – 1
Web site
Examples
4
INC and DEC Examples
.data
myWord WORD 1000h
myDword DWORD 10000000h
.code
inc myWord
dec myWord
inc myDword
mov
inc
mov
inc
ax,00FFh
ax
ax,00FFh
al
; 1001h
; 1000h
; 10000001h
; AX = 0100h
; AX = 0000h
Web site
Examples
5
Your turn...
Show the value of the destination operand after each
of the following instructions executes:
.data
myByte
.code
mov
mov
dec
inc
dec
BYTE 0FFh, 0
al,myByte
ah,[myByte+1]
ah
al
ax
;
;
;
;
;
AL
AH
AH
AL
AX
=
=
=
=
=
FFh
00h
FFh
00h
FEFF
Web site
Examples
6
ADD and SUB Instructions
• ADD destination, source
• Logic: destination  destination + source
• SUB destination, source
• Logic: destination  destination – source
• Same operand rules as for the MOV
instruction
Web site
Examples
7
ADD and SUB Examples
.data
var1 DWORD 10000h
var2 DWORD 20000h
.code
mov eax,var1
add eax,var2
add ax,0FFFFh
add eax,1
sub ax,1
;
;
;
;
;
;
---EAX--00010000h
00030000h
0003FFFFh
00040000h
0004FFFFh
Web site
Examples
8
NEG (negate) Instruction
Reverses the sign of an operand. Operand can be a register or
memory operand.
.data
valB SBYTE -1
valW WORD +32767
.code
mov al,valB
neg al
neg valW
; AL = -1
; AL = +1
; valW = -32767
Suppose AX contains –32,768 and we apply NEG to it. Will
the result be valid?
Web site
Examples
9
NEG Instruction and the Flags
The processor implements NEG using the following internal
operation:
SUB 0,operand
Any nonzero operand causes the Carry flag to be set.
.data
valB BYTE 1,0
valC SBYTE -128
.code
neg valB
neg [valB + 1]
neg valC
; CF = 1, OF = 0
; CF = 0, OF = 0
; CF = 1, OF = 1
Web site
Examples
10
Implementing Arithmetic
Expressions
HLL compilers translate mathematical expressions into
assembly language. You can do it also. For example:
Rval = -Xval + (Yval – Zval)
Rval DWORD ?
Xval DWORD 26
Yval DWORD 30
Zval DWORD 40
.code
mov eax,Xval
neg eax
mov ebx,Yval
sub ebx,Zval
add eax,ebx
mov Rval,eax
; EAX = -26
; EBX = -10
; -36
Web site
Examples
11
Your turn...
Translate the following expression into assembly language. Do
not permit Xval, Yval, or Zval to be modified:
Rval = Xval - (-Yval + Zval)
Assume that all values are signed doublewords.
mov
neg
add
mov
sub
mov
ebx,Yval
ebx
ebx,Zval
eax,Xval
eax,ebx
Rval,eax
Web site
Examples
12
Related documents