Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.

Slides:



Advertisements
Similar presentations
Instruction Set of 8086 Engr. M.Zakir Shaikh
Advertisements

ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
80x86 Instruction Set Dr. Qiang Lin.
Microprocessor System Design
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Intel’s 8086 instruction-set
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Microcomputer & Interfacing Lecture 3
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Suresh.P HOD / ECE MEA Engineering College Perinthalmanna
ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed.
Introduction to 8086 Assembly Language Assembly Language Programming University of Akron Dr. Tim Margush.
The x86 PC Assembly Language, Design, and Interfacing By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey © 2010, 2003, 2000, 1998 Pearson.
5. Assembly Language. Basics of AL Program data Pseudo-ops Array Program structures Data, stack, code segments.
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
8086 PROCESSOR UNIT I-B Mr. S. VINOD EEE DEPARTMENT
Addressing modes of 8086.
Review of Assembly language. Recalling main concepts.
Lecture 2 Chapter 4 –Requirements for coding in Assembly Language 1.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Assembly language programming
Instruction set Architecture
Format of Assembly language
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
Chapter instruction description and assembler directives from Microprocessors and Interfacing by Douglas Hall.
Today we are going to discuss about,
MASM 8086 Instruction - Basic Structure
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
Microprocessor Systems Design I
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
INSTRUCTION SET.
Microprocessor and Assembly Language
Machine control instruction
INSTRUCTION SET.
Assembly Language Programming Part 2
ECE 353 Introduction to Microprocessor Systems
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
UNIT: 2 INSTRUCTION SET OF 8086.
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
UNIT-I An Over View Of 8085 Architecture Of 8086 Microprocessor
Data formats or Instruction formats of 8086:
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
INTRODUCTION ABOUT ASSEMBLY
Chapter 4 –Requirements for coding in Assembly Language
University of Gujrat Department of Computer Science
Introduction to 8086 Assembly Language Programming
Chapter 5 Arithmetic and Logic Instructions
Assembler Directives end label end of program, label is entry point
Chapter 6 –Symbolic Instruction and Addressing
CNET 315 Microprocessor & Assembly Language
Chapter 8: Instruction Set 8086 CPU Architecture
Introduction to 8086 Assembly Language
Presentation transcript:

Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language

Data Representation Binary 0-1 represents the state of electronic components used in computer systems Bit - Binary digit Byte - 8 Bits smallest addressable memory location (on the IBM-PC) Word - 16 Bits Each architecture may define its own “wordsize” Doubleword - 32 Bits Quadword - 64 Bits Nybble - 4 Bits DB 8 DW 16 bits DD 32 bits DQ 64 bits

Defining Types of data – Array byte an array is a sequence of memory bytes or words. Example: B_ARRAYDB 10H,20H,30H W_ARRAYDW 1000,40,29887,329 Symbol Address Contents B_ARRAY 200H 10H B_ARRAY+1 201H 20H B_ARRAY+2 202H 30H W_ARRAY 203H 1000D W_ARRAY+2 205H 40D W_ARRAY+4 207H 29887D W_ARRAY+6 209H 329D

Addresses with Displacements b db 4Fh, 20h, 3Ch w dw 2048, -100, 0 mov bx, w+2 mov b+1, ah mov ah, b+5 mov dx, w-3 The assembler computes an address based on the expression NOTE: These are address computations done at assembly time MOV ax, b-1 will not subtract 1 from the value stored at b

Numeric Constant In an assembly language program, we may express data as: Binary: bit string followed by ‘B’ or ‘b’ Decimal: string of decimal digits followed by an optional ‘D’ or ‘d’ Hex: begins with a decimal digit and ends with ‘H’ or ‘h’ Real : end with ‘R’ and the assembler converts a given a decimal or hex constant to floating point number Any number may have an optional sign. The decimal range is: Unsigned representation: 0 to 255 Signed representation: -128 to 127 5

Numeric Constant Number Type B D 1,234 1B4DH 1B4D FFFFH 0FFFFH decimal binary decimal illegal hex illegal hex 6

Character String ASCII codes can be initialized with a string of characters using single quotes like ‘PC’ or double quotes like “PC”. Example: LETTERSDB'ABC' = LETTERSDB41H,42H,43H Inside a string, the assembler differentiates between upper and lower case. It is possible to combine characters and numbers in one definition: Example: MSGDB'HELLO',0AH,0DH, '$' 7

Named Constants - EQU (Equates) To assign a name to a constant, we can use the EQU pseudo-op. Syntax: name EQU constant Examples: LF EQU 0AH MOV DL,LF = MOV DL,0AH PROMPT EQU 'Any Thing' MSG DB 'Any Thing' = MSG DB PROMPT Note: no memory is allocated for EQU names. 8

Assembly Language Instructions Mnemonics represent Machine Instructions Each mnemonic used represents a single machine instruction The assembler performs the translation Some mnemonics require operands Operands provide additional information register, constant, address, or variable Assembler Directives

8086 Instruction - Basic Structure LabelOperatorOperand[s];Comment Label - optional alphanumeric string 1st character must be a-z, A-Z, _, $ Last character must be : Operator - assembly language instruction mnemonic: an instruction format for humans Assembler translates mnemonic into hexadecimal opcode example: mov is f8h Operand[s] - 0 to 3 pieces of data required by instruction Can be several different forms Delineated by commas immediate, register name, memory data, memory address Comment - Extremely useful in assembler language These fields are separated by White Space (tab, blank, \n, etc.)

8086 Instruction - Example LabelOperatorOperand[s];Comment INIT:movax, bx; Copy contents of bx into ax Label - INIT: Operator - mov Operands - ax and bx Comment -alphanumeric string between ; and \n Not case sensitive Unlike other assemblers, destination operand is first mov is the mnemonic that the assembler translates into an opcode

Instruction Set of 8086 Data moving instructions. –Data can be moved from register to register, register to memory and memory to register. Arithmetic - add, subtract, increment, decrement, convert byte/word and compare. Logic - AND, OR, exclusive OR, shift/rotate and test. String manipulation - load, store, move, compare and scan for byte/word. Control transfer - conditional, unconditional, call subroutine and return from subroutine. Input/Output instructions. Other - setting/clearing flag bits, stack operations, software interrupts, etc Lecture 2 :

x86 Instruction Set Summary (Data Transfer) CBW ;Convert Byte to Word AL  AX CWD ;Convert Word to Double in AX  DX,AX IN ;Input LAHF ;Load AH from Flags LDS ;Load pointer to DS LEA ;Load EA to register LES ;Load pointer to ES LODS ;Load memory at SI into AX MOV ;Move MOVS ;Move memory at SI to DI OUT ;Output POP ;Pop POPF ;Pop Flags PUSH ;Push PUSHF ;Push Flags SAHF ;Store AH into Flags STOS ;Store AX into memory at DI XCHG ;Exchange XLAT ;Translate byte to AL

x86 Instruction Set Summary (Arithmetic/Logical) AAA ;ASCII Adjust for Add in AX AAD ;ASCII Adjust for Divide in AX AAM ;ASCII Adjust for Multiply in AX AAS ;ASCII Adjust for Subtract in AX ADC ;Add with Carry ADD ;Add AND ;Logical AND CMC ;Complement Carry CMP ;Compare CMPS ;Compare memory at SI and DI DAA ;Decimal Adjust for Add in AX DAS ;Decimal Adjust for Subtract in AX DEC ;Decrement DIV ;Divide (unsigned) in AX(,DX) IDIV ;Divide (signed) in AX(,DX) MUL;Multiply (unsigned) in AX(,DX) IMUL ;Multiply (signed) in AX(,DX) INC ;Increment

x86 Instruction Set Summary (Arithmetic/Logical Cont.) NEG ;Negate NOT ;Logical NOT OR ;Logical inclusive OR RCL ;Rotate through Carry Left RCR ;Rotate through Carry Right ROL ;Rotate Left ROR ;Rotate Right SAR ;Shift Arithmetic Right SBB ;Subtract with Borrow SCAS ;Scan memory at DI compared to AX SHL/SAL ;Shift logical/Arithmetic Left SHR ;Shift logical Right SUB ;Subtract TEST ;AND function to flags XLAT ;Translate byte to AL XOR ;Logical Exclusive OR

x86 Instruction Set Summary (Control/Branch Cont.) CALL ;Call CLC ;Clear Carry CLD ;Clear Direction CLI ;Clear Interrupt ESC ;Escape (to external device) HLT ;Halt INT ;Interrupt INTO ;Interrupt on Overflow IRET ;Interrupt Return JB/JNAE ;Jump on Below/Not Above or Equal JBE/JNA ;Jump on Below or Equal/Not Above JCXZ ;Jump on CX Zero JE/JZ ;Jump on Equal/Zero JL/JNGE ;Jump on Less/Not Greater or Equal JLE/JNG ;Jump on Less or Equal/Not Greater JMP ;Unconditional Jump JNB/JAE ;Jump on Not Below/Above or Equal JNBE/JA ;Jump on Not Below or Equal/Above JNE/JNZ ;Jump on Not Equal/Not Zero JNL/JGE ;Jump on Not Less/Greater or Equal

Assembler Directives end labelend of program, label is entry point proc far|near begin a procedure; far, near keywords specify if procedure in different code segment (far), or same code segment (near) endpend of procedure pageset a page format for the listing file titletitle of the listing file.codemark start of code segment.datamark start of data segment.stackset size of stack segment

x86 Instruction Set Summary (Control/Branch) JNLE/JG ;Jump on Not Less or Equal/Greater JNO ;Jump on Not Overflow JNP/JPO ;Jump on Not Parity/Parity Odd JNS ;Jump on Not Sign JO ;Jump on Overflow JP/JPE ;Jump on Parity/Parity Even JS ;Jump on Sign LOCK ;Bus Lock prefix LOOP ;Loop CX times LOOPNZ/LOOPNE ;Loop while Not Zero/Not Equal LOOPZ/LOOPE ;Loop while Zero/Equal NOP ;No Operation (= XCHG AX,AX) REP/REPNE/REPNZ;Repeat/Repeat Not Equal/Not Zero REPE/REPZ ;Repeat Equal/Zero RET ;Return from call SEG ;Segment register STC ;Set Carry STD ;Set Direction STI ;Set Interrupt TEST ;AND function to flags WAIT ;Wait

Assembler Directives dbdefine byte dwdefine word (2 bytes) dddefine double word (4 bytes) dqdefine quadword (8 bytes) dtdefine tenbytes equequate, assign numeric expression to a name Examples: db 100 dup (?) define 100 bytes, with no initial values for bytes db “Hello”define 5 bytes, ASCII equivalent of “Hello”. maxintequ32767 countequ10 * 20 ; calculate a value (200)

Program Example ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; This is an example program. It prints the ; ; character string "Hello World" to the DOS standard output ; ; using the DOS service interrupt, function 9. ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; hellostk SEGMENT BYTE STACK 'STACK' ;Define the stack segment DB 100h DUP(?) ;Set maximum stack size to 256 bytes (100h) hellostk ENDS hellodat SEGMENT BYTE 'DATA' ;Define the data segment dos_print EQU 9 ;define a constant via EQU strng DB 'Hello World',13,10,'$' ;Define the character string hellodat ENDS hellocod SEGMENT BYTE 'CODE' ;Define the Code segment START: mov ax, SEG hellodat ;ax <-- data segment start address mov ds, ax ;ds <-- initialize data segment register mov ah, dos_print ;ah <-- 9 DOS 21h string function mov dx,OFFSET strng ;dx <-- beginning of string int 21h ;DOS service interrupt mov ax, 4c00h ;ax <-- 4c DOS 21h program halt function int 21h ;DOS service interrupt hellocod ENDS END START ; ‘END label’ defines program entry

Creating and Running a Program Editor.ASM file Assembler.OBJ file Linker.EXE file A text editor or word processor is used to create a source program file. An assembler is used to translate the source file into a machine language object file. Assembling: translate source program (written in assembly language) into machine code (object code) A linker is used to link one or more object files to create a run file. Linking: complete machine code for the object program, generate an executable module

Step 2: Assembling & Linking the program After printing the copyright information, the assembler will check the source file for syntax errors: If one or more errors were found: The assembler will display the line number of each error and a short description. If no errors were found: The assembler will translate the assembly language code into the assembly machine language object file (.obj file). The linker will take one or more object files, fills any missing addresses, and combines the object files into a single executable file (.exe file).