Prof. Muhammad Saeed III. 1/27/2015Computer Architecture & Assembly Language2 Assembly Language Instructions.

Slides:



Advertisements
Similar presentations
Jump Condition.
Advertisements

Computer Organization And Assembly Language
Department of Computer Science and Software Engineering
Computer Organization And Assembly Language
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
Assembly Language for Intel-Based Computers Chapter 8: Advanced Procedures Kip R. Irvine.
Prof. Muhammad Saeed III. 1/27/2015Computer Architecture & Assembly Language2 Assembly Language Instructions.
1 Lecture 4: Data Transfer, Addressing, and Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language for Intel-Based Computers
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
Basic Instructions Addressing Modes
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
Lecture 3 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Faculty of Engineering, Electrical Department,
Computer Architecture and Assembly Language Practical session outline Introduction 80x86 assembly –Data storage –The registers –Flags –Instructions Assignment.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Basic Instructions Addressing Modes
Computer Architecture and Assembly Language. Byte structure : a byte has 8 bits MSB (Most Significant Bit) LSB (Least Significant Bit) Data Representation.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Arithmetic Flags and Instructions
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
(Flow Control Instructions)
1 ICS 51 Introductory Computer Organization Fall 2009.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Chapter 5 Branching and Looping.
1 The Stack and Procedures Chapter 5. 2 A Process in Virtual Memory  This is how a process is placed into its virtual addressable space  The code is.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
Conditional Loop Instructions, Conditional Structures
MOV Instruction MOV destination,source  MOV AX,BX  MOV SUM,EAX  MOV EDX,ARRAY[EBX][ESI]  MOV CL,5  MOV DL,[BX]
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Computer Architecture and Assembly Language
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
CSC 221 Computer Organization and Assembly Language Lecture 20: Conditional and Block Structures.
Assembly Language for Intel-Based Computers, 4 th Edition Week 10: Conditional Processing Slides modified by Dr. Osama Younes.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
CS2422 Assembly Language and System Programming 0 Week 9 Data Transfers, Addressing, and Arithmetic.
Computer Architecture and Assembly Language
CSC 221 Computer Organization and Assembly Language
Stack Operations Dr. Hadi AL Saadi.
Computer Architecture and Assembly Language
Data Transfers, Addressing, and Arithmetic
Homework Reading Labs PAL, pp
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
Assembly IA-32.
Assembly Language Lab (4).
More on logical instruction and
Assembly Language Programming Part 2
CS 301 Fall 2002 Assembly Instructions
Computer Organization and Assembly Language
Data Transfers, Addressing, and Arithmetic
Practical Session 4.
Computer Architecture CST 250
CNET 315 Microprocessor & Assembly Language
CSC 497/583 Advanced Topics in Computer Security
Chapter 8: Instruction Set 8086 CPU Architecture
Computer Organization and Assembly Language
Computer Architecture and Assembly Language
Computer Architecture and System Programming Laboratory
Presentation transcript:

Prof. Muhammad Saeed III

1/27/2015Computer Architecture & Assembly Language2 Assembly Language Instructions

1/27/2015Computer Architecture & Assembly Language3 MOV reg, reg MOV mem, reg MOV reg, mem MOV mem, imm MOV reg, imm Language Instructions †MOV MOVZX reg32, reg/mem8 MOVZX reg32, reg/mem16 MOVZX reg16, reg/mem8 †MOVZX MOVSX reg32, reg/mem8 MOVSX reg32, reg/mem16 MOVSX reg16, reg/mem8 †MOVSX

1/27/2015Computer Architecture & Assembly Language4 †XCHG XCHG reg, reg XCHG reg, mem XCHG mem, reg INC reg/mem DEC reg/mem †INC, DEC The Overflow, Sign, Zero, Auxiliary Carry, and Parity flags are changed according to the value of the destination operand. †ADD, SUB ADD dest, source The Carry, Zero, Sign, Overflow, Auxiliary Carry, and Parity flags are changed according to the value that is placed in the destination operand. SUB dest, source NEG reg NEG mem †NEG The Carry, Zero, Sign, Overflow, Auxiliary Carry, and Parity flags are changed according to the value that is placed in the destination operand. Language Instructions

The PUSH instruction first decrements ESP and then copies a source operand into the stack. A 16-bit operand causes ESP to be decremented by 2. A 32-bit operand causes ESP to be decremented by 4. †PUSH †POP PUSH reg/mem16 PUSH reg/mem32 PUSH imm32 The POP instruction first copies the contents of the stack element pointed to by ESP into a 16- or 32-bit destination operand and then increments ESP. If the operand is 16 bits, ESP is incremented by 2; if the operand is 32 bits, ESP is incremented by 4 POP reg/mem16 POP reg/mem32 Language Instructions

†PUSHFD and POPFD The PUSHFD instruction pushes the 32-bit EFLAGS register on the stack, and POPFD pops the stack into EFLAGS. †PUSHAD and POPAD The PUSHAD instruction pushes all of the 32-bit general-purpose registers on the stack in the given order: EAX, ECX, EDX, EBX, ESP, EBP, ESI, and EDI. The POPAD instruction pops the same registers off the stack in reverse order. †PUSHA and POPA PUSHA instruction, pushes the 16-bit general-purpose registers (AX, CX, DX, BX, SP, BP, SI, DI) on the stack in the order listed. The POPA instruction pops the same registers in reverse Language Instructions

†LOOP The LOOP instruction assumes that the ECX (or CX) register contains the loop count. When the loop instruction is executed, the CX register is decremented and the control jumps to the target label, until the CX register value reaches zero. Language Instructions †Unconditional Jump Jmp label1

Language Instructions InstructionDescriptionFlags tested JE/JZJump Equal or Jump ZeroZF JNE/JNZJump not Equal or Jump Not ZeroZF JG/JNLEJump Greater or Jump Not Less/Equal OF, SF, ZF JGE/JNLJump Greater or Jump Not LessOF, SF JL/JNGEJump Less or Jump Not Greater/Equal OF, SF JLE/JNGJump Less/Equal or Jump Not Greater OF, SF, ZF †Conditional Jumps Following are the conditional jump instructions used on signed data

Language Instructions †Conditional Jumps Following are the conditional jump instructions used on unsigned data InstructionDescriptionFlags tested JE/JZJump Equal or Jump ZeroZF JNE/JNZJump not Equal or Jump Not ZeroZF JA/JNBEJump Above or Jump Not Below/EqualCF, ZF JAE/JNBJump Above/Equal or Jump Not BelowCF JB/JNAEJump Below or Jump Not Above/EqualCF JBE/JNAJump Below/Equal or Jump Not AboveAF, CF

Language Instructions †Conditional Jumps The following conditional jump instructions have special uses and check the value of flags InstructionDescriptionFlags tested JXCZJump if CX is Zeronone JCJump If CarryCF JNCJump If No CarryCF JOJump If OverflowOF JNOJump If No OverflowOF JP/JPEJump Parity or Jump Parity EvenPF JNP/JPOJump No Parity or Jump Parity OddPF JSJump Sign (negative value)SF JNSJump No Sign (positive value)SF

†AND AND reg,reg AND reg,mem AND reg,imm AND mem,reg AND mem,imm The AND instruction performs a boolean (bitwise) AND operation between each pair of matching bits in two operands and places the result in the destination operand †OR The OR instruction performs a boolean OR operation between each pair of matching bits in two operands and places the result in the destination operand OR reg,reg OR reg,mem OR reg,imm OR mem,reg OR mem,imm Language Instructions

†XOR The XOR instruction performs a boolean exclusive-OR operation between each pair of matching bits in two operands and stores the result in the destination operand OR reg,reg OR reg,mem OR reg,imm OR mem,reg OR mem,imm †NOT The NOT instruction toggles (inverts) all bits in an operand NOT reg NOT mem Language Instructions

†TEST Language Instructions The TEST instruction performs an implied AND operation between each pair of matching bits in two operands and sets the Sign, Zero, and Parity flags based on the value assigned to the destination operand. The only difference between TEST and AND is that TEST does not modify the destination operand. The TEST instruction always clears the Overflow and Carry flags. It modifies the Sign, Zero, and Parity flags in the same way as the AND instruction.

Language Instructions †CMP In x86 assembly language we use the CMP instruction to compare integers. Character codes are also integers, so they work with CMP as well. The CMP (compare) instruction performs an implied subtraction of a source operand from a destination operand. Neither operand is modified. CMP uses the same operand combinations as the AND instruction.

Language Instructions †Directive †Instruction †Procedure  myproc PROC …… ret myproc endp (call myproc) †Macro  myMacro MACRO …….. endm(myMacro)

†PTR Operator PTR operator overrides the declared size of an operand to access the operand using a size attribute that is different from the one assumed by the assembler. MOV eax, WORD PTR [var] †LENGTHOF Operator The LENGTHOF operator counts the number of elements in an array Language Instructions Var1 WORD 20 DUP(0) Var2DWORD 20 DUP(0) LENGTHOF var1 †SIZEOF Operator Var1 WORD 20 DUP(0) Var2DWORD 20 DUP(0) SIZEOF var1 The SIZEOF operator counts the number of bytes in an array †($ - array) Array BYTE “WELCOME”, 0dh, 0ah Size WORD( $-Array )

†LABEL Directive The LABEL directive gives a size attribute without allocating any storage Language Instructions.DATA val16 LABEL WORD val32 DWORD h.CODE mov ax,val16 mov dx,[val16+2].DATA LongValue LABEL DWORD val1 WORD 5678h val2 WORD 1234h.CODE mov eax,LongValue

Language Instructions †Indexed Operand An indexed operand adds a constant to a register to generate an effective address.DATA array BYTE 10h, 20h, 30h.CODE mov esi,0 mov al,array[esi] †Scale Factors in Indexed Operand.DATA ArrayDWORD 100h, 200h, 300h, 400h.CODE mov esi, 3 * TYPE array mov eax,array[esi]

Language Instructions

1/27/2015Computer Architecture & Assembly Language21 Program 1 st Program.586.MODEL flat, stdcall option casemap :none Include D:\msaeed\academic\assemblylanguage\masm32\include\windows.inc Include D:\msaeed\academic\assemblylanguage\masm32\include\kernel32.inc Include D:\msaeed\academic\assemblylanguage\masm32\include\user32.inc Includelib D:\msaeed\academic\assemblylanguage\masm32\lib\kernel32.lib Includelib D:\msaeed\academic\assemblylanguage\masm32\lib\user32.lib.DATA WindowTitle BYTE “Greetings",0 Message BYTE “Hello, World",0.CODE main: invoke MessageBox, NULL, ADDR Message, ADDR WindowTitle, MB_OK invoke ExitProcess, eax end main

END