Morgan Kaufmann Publishers Computer Organization and Assembly Language

Slides:



Advertisements
Similar presentations
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Advertisements

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.
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
Fundamentals of Assembly language
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h  Int 21 –A hexadecimal.
Introduction to 8086 Assembly Language Assembly Language Programming University of Akron Dr. Tim Margush.
Chapter Five–80x86 Assembly program development Principles of Microcomputers 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 1.
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
Review of Assembly language. Recalling main concepts.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Lecture 2 Chapter 4 –Requirements for coding in Assembly Language 1.
Assembly language programming
Format of Assembly language
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Assembly Language programming
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
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
INTRODUCTION ABOUT ASSEMBLY
Computer Organization & Assembly Language
Microprocessor & Interfacing
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
Introduction to Assembly Language
Flags Register & Jump Instruction
Lecture 1 Instruction set of 8086 Лектор: Люличева И.А. 1.
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
Program Logic and Control
Program Logic and Control
Chapter 4 –Requirements for coding in Assembly Language
Symbolic Instruction and Addressing
Chapter 4 –Requirements for coding in Assembly Language
Morgan Kaufmann Publishers Computer Organization and Assembly Language
INTRODUCTION ABOUT ASSEMBLY
Chapter 4 –Requirements for coding in Assembly Language
Requirements for coding in Assembly Language
Introduction to 8086 Assembly Language Programming
Chapter 5 Arithmetic and Logic Instructions
Assembler Directives end label end of program, label is entry point
Computer Architecture and System Programming Laboratory
Chapter 6 –Symbolic Instruction and Addressing
CNET 315 Microprocessor & Assembly Language
Chapter 7 –Program Logic and Control
Chapter 8: Instruction Set 8086 CPU Architecture
Chapter 7 –Program Logic and Control
Computer Architecture and Assembly Language
Introduction to 8086 Assembly Language
Presentation transcript:

Morgan Kaufmann Publishers Computer Organization and Assembly Language August 25, 2018 CS 206 D Computer Organization and Assembly Language Chapter 1 — Computer Abstractions and Technology

Introduction to 8086 Assembly Language 01/22/08 Introduction to 8086 Assembly Language Assembly Language Programming

MOV CX, 0 ; CX counts terms, initially 0 01/22/08 Program Statements Assembly Language Features 1- Program comments 2-Reserved 3-Words Identifiers 4-Statements 5- Directives Comments begin with semicolon and the assembler ignores anything typed after the semicolon. MOV CX, 0 ; CX counts terms, initially 0 Operation is a predefined or reserved word (MOV; ADD) mnemonic - symbolic operation code directive – pseudo - operation code (END) Space or tab separates initial fields Most assemblers are not case sensitive

Program Data and Storage 01/22/08 Pseudo-ops to define data or reserve storage DB - byte(s)‏ DW - word(s)‏ DD - doubleword(s)‏ DQ - quadword(s)‏ DT - tenbyte(s)‏ These directives require one or more operands define memory contents specify amount of storage to reserve for run-time data Bit - Binary digit Byte - 8 Bits smallest addressable memory location

Identifiers Can be from 1 to 31 characters long (not case sensitive). May consist of letters, digits, and the special characters ? . @ _ $ % (Thus, embedded blanks are not allowed). Names may not begin with a digit. If a dot is used, it must be the first character. Examples: COUNTER1 2abc @CHARACTER A45. 28 TWO WORDS STD_NUM .TEST Begins with a digit . Not first character Contains a blank YOU&ME Contains an illegal character

01/22/08 Named Constants Symbolic names associated with storage locations represent addresses Named constants are symbols created to represent specific values determined by an expression Named constants can be numeric or string Some named constants can be redefined No storage is allocated for these values

Naming Storage Locations 01/22/08 Names can be associated with storage locations Var1 DB 255,?,-128,'X' ANum DB -4 DW 17 X DD ? Anum, X and Var1 names are called variables A list of values may be used - the Var1 creates 4 consecutive bytes ANum refers to a byte storage location, initialized to FCh ?? Negative numbers are represented by its 2’s complement The next word has no associated name A ? represents an uninitialized storage location X is an unitialized double word

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 Number Type 11011 1101B 64223 -21843D 1,234 1B4DH 1B4D FFFFH 0BFFFH decimal binary illegal hex

Defining Types of data – Array an array is a sequence of memory bytes or words. Example: Org 200H B_ARRAY DB 10H,20H,30H W_ARRAY DW 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

DUP Allows a sequence of storage locations to be defined or reserved 01/22/08 Allows a sequence of storage locations to be defined or reserved Only used as an operand of a define directive DB 40 DUP (?)‏ ; 40 unitialized bytes DW 10h DUP (0)‏ ; 16 words with zero ; initial values DB 3 dup ("ABC") ; means sequence ;"ABC" three times ;"ABCABCABC"

Word Storage 01/22/08 Word, doubleword, and quadword data are stored in reverse byte order (in memory)‏ Directive Bytes in Storage DW 256 00 01 DD 1234567H 67 45 23 01 DQ 10 0A 00 00 00 00 00 00 00 X DW 35DAh DA 35 Low byte of X is at X, high byte of X is at X+1

Equal Sign Directive (=) 01/22/08 name = expression expression must be numeric these symbols may be redefined at any time DW count (?) count = 1 Sum = count * 2 = expressions are evaluated where defined

EQU Directive name EQU expression expression can be string or numeric 01/22/08 name EQU expression expression can be string or numeric Use < and > to specify a string EQU these symbols cannot be redefined later in the program sample EQU 7Fh aString EQU <1.234> message EQU <This is a message> Note: no memory is allocated for EQU names. EQU expressions are evaluated where used

Statements Both instructions and directives have up to four fields: [identifier ] operation [operand(s)] [comment] [Name Fields are optional] At least one blank or tab character must separate the fields. The fields do not have to be aligned in a particular column, but they must appear in the above order. An example of an instruction: START: MOV CX,5 ; initialize counter An example of an assembler directive: MAIN PROC

Program Segment Structure 01/22/08 .SEGMENT Directive .END Directive ENDP directive ends a procedure END directive ends the entire program and appears as the last statement Each segment can not be larger than 64K byte=216 byte Data Segments Storage for variables Variable addresses are computed as offsets from start of this segment Code Segment contains executable instructions Stack Segment used to set aside storage for the stack Stack addresses are computed as offsets into this segment Segment directives .data .code .stack size

Program Structure - Stack Segment The purpose of the stack segment declaration is to set aside a block of memory (the stack area) to store the stack. The stack area should be big enough to contain the stack at its maximum size. Syntax: .STACK size ; where size is an optional number that specifies ; the stack area size in bytes. Example: .STACK 100H ; sets aside 100H bytes for the stack area. ; (reasonable size for most applications). If size is omitted, 1KB is set aside for the stack area.

Program Structure - Data Segment A program’s data segment contains all the variable definitions. Constant definitions are often made here as well. (they may be placed elsewhere in the program since no memory allocation is involved). To declare a data segment, we use the directive .DATA, followed by variable and constant declarations. Example: .DATA WORD1 DW 2 MSG DB ‘this is a message’

Program Structure - Code Segment The code segment contains a program’s instructions. Syntax: .CODE name ; where name is an optional name of segment. There is no need for a name in a SMALL program, However, the assembler will generate an error. Inside a code segment, instructions are organized as procedures. The simplest procedure definition is: name PROC ; name: is the name of the procedure. ; body of the procedure ; PROC & ENDP: are pseudo-ops that name ENDP ; delineate the procedure Example of a code segment definition: .CODE MAIN PROC ; main procedure instructions MAIN ENDP ; other procedures go here

Program Structure Memory Models 01/22/08 Program Structure Memory Models The size of code and data that a program can have, is determined by specifying a memory model using the .MODEL directive. Syntax: .MODEL memory_model Model Description SMALL code in 1 segment data in 1 segment MEDIUM code > 1 segment data in 1 segment COMPACT code in 1 segment data > 1 segment LARGE code > 1 segment data > 1 segment no array larger than 64k bytes HUGE code > 1 segment data > 1 segment arrays may be larger than 64k bytes

Program Skeleton .model small .stack 100H .data ;declarations .code 01/22/08 Program Skeleton .model small .stack 100H .data ;declarations .code main proc ;code main endp ;other procs end main Select a memory model Define the stack size Declare variables Write code organize into procedures Mark the end of the source file optionally, define the entry point

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 label end 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) endp end of procedure page set a page format for the listing file title title of the listing file .code mark start of code segment .data mark start of data segment .stack set 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

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, 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 hellocod ENDS END START ; ‘END label’ defines program entr

Creating and Running a Program A text editor or word processor is used to create a source program file. Editor .ASM 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) Assembler .OBJ file Linker 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 .EXE file

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).