Review of Assembly language. Recalling main concepts.

Slides:



Advertisements
Similar presentations
Registers of the 8086/ /2002 JNM.
Advertisements

Assembly Programming Notes for Practical2 Munaf Sheikh
Introduction to 8086 Microprocessor
Computer Organization & Assembly Language
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
Video systems (continue). Practice Modify the program to get a string from a keyboard to display the input string on the middle of the screen with reverse.
The 8086 Assembly Programming Data Allocation & Addressing Modes
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
Direct video practice and Keyboard Operations
Princess Sumaya University
Irvine: Assembly Language for Intel-Based Computers (1999) Symbolic Constants Equal-sign Directive EQU Directive TEXTEQU Directive.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
6.1) Assembly Language Program Format 6.2) Features of Assembly Language 6.3) Data Definition CHAPTER 6 ASSEMBLY LANGUAGE PROGRAM FORMAT AND DATA DEFINITION.
Microcomputer & Interfacing Lecture 3
Fundamentals of Assembly language
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Introduction to 8086 Assembly Language Assembly Language Programming University of Akron Dr. Tim Margush.
Faculty of Engineering, Electrical Department,
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.
Chapter 4 Requirements for Coding in Assembly Language.
Strings, Procedures and Macros
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
Processing String Data and Binary Data (continue)
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
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.
Microprocessors used in Personal Computers. The Memory Map of a Personal Computers Transient Program Area (TPA): Holds the operating system (interrupt.
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.
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
2/20/2016CAP 2211 Flow Control Instructions. 2/20/2016CAP 2212 Transfer of Control Flow control instructions are used to control the flow of a program.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
Assembly language programming
Instruction set Architecture
Introduction to assembly programmıng language
Format of Assembly language
Data Transfers, Addressing, and Arithmetic
8086 Microprocessor.
ADDRESSING MODES.
Microprocessor Systems Design I
Microprocessor and Assembly Language
INSTRUCTION SET.
Microprocessor and Assembly Language
Assembly IA-32.
INSTRUCTION SET.
Assembly Language Programming Part 2
ADDRESSING MODES.
Intel 8088 (8086) Microprocessor Structure
Computer Organization & Assembly Language
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Introduction to Assembly Language
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
ارايه دهنده : حسن عسكرزاده
Intel 8088 (8086) Microprocessor Structure
8086 Registers Module M14.2 Sections 9.2, 10.1.
اصول اساسی برنامه نویسی به زبان اسمبلی
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
(Array and Addressing Modes)
Symbolic Instruction and Addressing
(Array and Addressing Modes)
Assembler Directives end label end of program, label is entry point
Computer Architecture and System Programming Laboratory
UNIT-II Assembly Language Programs Involving Logical
Chapter 6 –Symbolic Instruction and Addressing
Chapter 8: Instruction Set 8086 CPU Architecture
Introduction to 8086 Assembly Language
UNIT-II ADDRESSING MODES & Instruction set
(Array and Addressing Modes)
Presentation transcript:

Review of Assembly language

Recalling main concepts

Segment: special areas defined to contain CODE, DATA and STACK Paragraph boundary: location evenly divisible by 16 or 10H

Recalling main concepts Stack Segment Data Segment Code Segment SS DS CS Segment Registers

Example program ; Add two numbers and store the results into the third variable page 60,132 TITLEA04ASM1 (EXE) Move and add operations ; STACKSEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACKENDS ; DATASEGSEGMENT PARA 'Data' FLDDDW 215 FLDEDW 125 FLDFDW ? DATASEGENDS ; CODESEGSEGMENT PARA 'Code' MAINPROC FAR ASSUME SS:STACK,DS:DATASEG,CS:CODESEG MOV AX,DATASEG;Set address of data MOV DS,AX; segment in DS MOV AX,FLDD;Move 0215 to AX ADD AX,FLDE;Add 0125 to AX MOV FLDF,AX;Store sum in FLDF MOV AX,4C00H;End processing INT 21H MAINENDP;End of procedure CODESEGENDS;End of segment END MAIN;End of program

; Add two numbers and store the results into the third variable page 60,132 TITLEA04ASM1 (EXE) Move and add operations ; STACKSEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACKENDS ; DATASEGSEGMENT PARA 'Data' FLDDDW 215 FLDEDW 125 FLDFDW ? DATASEGENDS ; CODESEGSEGMENT PARA 'Code' MAINPROC FAR ASSUME SS:STACK,DS:DATASEG,CS:CODESEG MOV AX,DATASEG;Set address of data MOV DS,AX;Segment in DS MOV AX,FLDD;Move 0215 to AX ADD AX,FLDE;Add 0125 to AX MOV FLDF,AX;Store sum in FLDF MOV AX,4C00H;End processing INT 21H MAINENDP;End of procedure CODESEGENDS;End of segment END MAIN;End of program Comments ; COMMENTS

; Add two numbers and store the results into the third variable page 60,132 TITLEA04ASM1 (EXE) Move and add operations ; STACKSEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACKENDS ; DATASEGSEGMENT PARA 'Data' FLDDDW 215 FLDEDW 125 FLDFDW ? DATASEGENDS ; CODESEGSEGMENT PARA 'Code' MAINPROC FAR ASSUME SS:STACK,DS:DATASEG,CS:CODESEG MOV AX,DATASEG;Set address of data MOV DS,AX;Segment in DS MOV AX,FLDD;Move 0215 to AX ADD AX,FLDE;Add 0125 to AX MOV FLDF,AX;Store sum in FLDF MOV AX,4C00H;End processing INT 21H MAINENDP;End of procedure CODESEGENDS;End of segment END MAIN;End of program IDENTIFIERS

Identifiers Identifier is a name applied to an item in a program to reference Name (e.g: FLDDDW 215) Label (e.g: MAINPROC FAR) Identifiers must not a reserved word and only contain: Alphabetic letters (A-Z,a-z) Digits (0-9) (.) (but not for the first character) Maximum length is 247 IDENTIFIERS

Instructions: ADD, MOV Directives:.TITLE,.MODEL Operators: FAR, SIZE Register: AX,BX RESERVED WORDS

STATEMENT Instructions: are translated to object code MOV, ADD, LEA.. Directives: tell the assembler to perform a specific action. [identifier] operation [operand(s)] [;comments]

; Add two numbers and store the results into the third variable page 60,132 TITLEA04ASM1 (EXE) Move and add operations ; STACKSEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACKENDS ; DATASEGSEGMENT PARA 'Data' FLDDDW 215 FLDEDW 125 FLDFDW ? DATASEGENDS ; CODESEGSEGMENT PARA 'Code' MAINPROC FAR ASSUME SS:STACK,DS:DATASEG,CS:CODESEG MOV AX,DATASEG;Set address of data MOV DS,AX;Segment in DS MOV AX,FLDD;Move 0215 to AX ADD AX,FLDE;Add 0125 to AX MOV FLDF,AX;Store sum in FLDF MOV AX,4C00H;End processing INT 21H MAINENDP;End of procedure CODESEGENDS;End of segment END MAIN;End of program STATEMENTS

Directives Control the way a source program assembles and lists Generate no machine code (unlike instructions which generate object code)

; Add two numbers and store the results into the third variable page 60,132 TITLEA04ASM1 (EXE) Move and add operations ; STACKSEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACKENDS ; DATASEGSEGMENT PARA 'Data' FLDDDW 215 FLDEDW 125 FLDFDW ? DATASEGENDS ; CODESEGSEGMENT PARA 'Code' MAINPROC FAR ASSUME SS:STACK,DS:DATASEG,CS:CODESEG MOV AX,DATASEG;Set address of data MOV FLDF,AX;Store sum in FLDF MOV AX,4C00H;End processing INT 21H MAINENDP;End of procedure CODESEGENDS;End of segment END MAIN;End of program Segment directive

NameOperationOperand Segment-nameSEGMENT[align][combine] [`class’] Segment-nameENDS Example: STACKSEGMENT PARA STACK 'Stack‘ STACK ENDS

; Add two numbers and store the results into the third variable page 60,132 TITLEA04ASM1 (EXE) Move and add operations ; STACKSEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACKENDS ; DATASEGSEGMENT PARA 'Data' FLDDDW 215 FLDEDW 125 FLDFDW ? DATASEGENDS ; CODESEGSEGMENT PARA 'Code' MAINPROC FAR ASSUME SS:STACK,DS:DATASEG,CS:CODESEG MOV AX,DATASEG;Set address of data MOV DS,AX;Segment in DS MOV AX,FLDD;Move 0215 to AX MOV FLDF,AX;Store sum in FLDF MOV AX,4C00H;End processing INT 21H MAINENDP; End of procedure CODESEGENDS;End of segment END MAIN;End of program PROC directive

Format: Procedure-namePROC Operand Comment Procedure-nameENDP Operand: relates to program execution (FAR)

; Add two numbers and store the results into the third variable page 60,132 TITLEA04ASM1 (EXE) Move and add operations ; STACKSEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACKENDS ; DATASEGSEGMENT PARA 'Data' FLDDDW 215 FLDEDW 125 FLDFDW ? DATASEGENDS ; CODESEGSEGMENT PARA 'Code' MAINPROC FAR ASSUME SS:STACK,DS:DATASEG,CS:CODESEG MOV AX,DATASEG;Set address of data MOV DS,AX;Segment in DS MOV AX,FLDD;Move 0215 to AX MOV FLDF,AX;Store sum in FLDF MOV AX,4C00H;End processing INT 21H MAINENDP;End of procedure CODESEGENDS;End of segment END MAIN;End of program ASSUME directive

Tells the assembler the purpose of each segment in the program Example: ASSUME SS:STACK,DS:DATASEG,CS:CODESEG

Simplified Segment Directives Model memory-model # Code segment#Data segment Small: 1, <=64K1,<=64K Medium: any number,size 1, <=64K Compact: 1, <=64K any number,size Large: any number,size any number,size Huge: any number,size any number,size

Simplified Segment Directives STACK [size] (default: 1K) DATA (default size is 1K) CODE (default size is 1K).EXIT directive

EQUATE directives Equal-Sign directive COEFFICIENT= 100 EQU directive COEFFICIENT EQU 100

Data type Format for data definition [name] Dn expression Name: identifier Dn: Directives and can be: DB: byteDF:farword DW: wordDQ:quadword DD: doublewordDT:tenbytes Expression: can be unnitialized: ? can be assigned a constant: such as 25, 21. Example: DATAZ DB 21,22.. DW 10 DUP(?)

Data type Constant: String: is defined within ‘ ‘ or “ “ MESSAGE DB “I am learning assembly language” Numeric: Is stored in reverse sequence Binary: 01B Decimal: 9D( D is optional) Hexadecimal: 1FH Real: 12R

Directives for defining Data Byte: DB Word: DW Doubleword: DD Farword: DF Quadword: DQ Tenbytes: DT

Some instructions on arithmetic calculation ADD: ADD registerregister/memory/immediate Example:ADD AX,FLDE Subtract SBB register register/memory/immediate Example:SUB AX, 100 Multiplication IMUL register Example:IMULCX Division DIV register ExampleDIVCX

Data transfer instructions MOV instruction Transfers data referenced by the address of the second operand to the address of the first operand Destination has to have the same length as source [label:] MOV register/memory register/memory/immediate Example: MOV F, AX; // Move content of AX to the variable F MOV CX, D;// Move value of D to CX MOV ES, AX MOV AX, 215

Note MOV instruction can’t: set the value of the CS and IP registers. copy value of one segment register to another segment register (should copy to general register first). MOV ES, DS copy immediate value to segment register (should copy to general register first). MOV DS, 100 MOV instruction can’t: set the value of the CS and IP registers. copy value of one segment register to another segment register (should copy to general register first). MOV ES, DS copy immediate value to segment register (should copy to general register first). MOV DS, 100

MOVSB: Copy byte at DS:[SI] to ES:[DI]. Update SI and DI. Algorithm: ES:[DI] = DS:[SI] if DF = 0 then SI = SI + 1 DI = DI + 1 else SI = SI - 1 DI = DI - 1 DF: direction flag from the flag register MOVSB and MOVSW

MOVSW: Copy word at DS:[SI] to ES:[DI]. Update SI and DI. ES:[DI] = DS:[SI] if DF = 0 then SI = SI + 2 DI = DI + 2 else SI = SI - 2 DI = DI - 2 DF: direction flag from the flag register MOVSB and MOVSW

XCHG swap the two data items [label:] XCHG register/memory, register/memory Example: MOV AL, 5 MOV AH, 2 XCHG AL, AH ; AL = 2, AH = 5 XCHG AL, AH ; AL = 5, AH = 2 XCHG instruction

Load Effective Address. REG = address of memory (offset) [label:] LEA register/memory Example: LEA AX, m ;load offset address of m to AX LEA instruction

Arithmetic instructions INC and DEC instruction Increasing or decreasing the contents of register or memory location by 1 [label:] INC/DEC register/memory Flag: OF, SF and ZF OF:is set when an instruction resulted in a carry into the sign bit of the result. SF: is set if the sign bit of a result is set ZF: is set if the result is equal to 0.

Arithmetic instructions ADD [label:] ADD/SUB operand1, operand 2 operand1 =operand 1 + operand 2 Operand 1: register/memory Operand 2: register/memory/immediate

Arithmetic instructions SUB [label:] SUB operand1, operand 2 operand1 =operand 1 - operand 2 operand 1: register/memory operand 2: register/memory/immediate

Arithmetic instructions MULoperand Unsigned multiply. Operand: register/memory

Arithmetic instructions IMULoperand Signed multiply. Operand: register/memory Example: MOV AX, -2 MOV CX, -3 IMUL CX; AX = +6 CF = 0

Arithmetic instructions DIVoperand Unsigned multiply. Operand: register/memory when operand is a byte: AL = AX / operand AH = remainder (modulus) when operand is a word: DX = remainder (modulus)

Arithmetic instructions IDIVoperand Signed multiply. Operand: register/memory when operand is a byte: AL = AX / operand AH = remainder (modulus) when operand is a word: DX = remainder (modulus)

Repetitive move instructions TITLEA04ASM1 (EXE) Move and add operations ; STACKSEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACKENDS ; DATASEGSEGMENT PARA 'Data' STRING1 DW " ","$" STRING2 DW ? DATASEGENDS

Repetitive move instructions MAINPROC FAR MOV AX, dataseg MOV DS, AX MOV ES, AX MOV CX, 09 ; Initialize to move 9 characters LEA SI, STRING1 ; Initialize source index register to offset of string 1 LEA DI, STRING2 ; Initialize destination index register to offset of string 2 BEGINLOOP: MOV AL,[SI] ; Get a current character from string 1 to AL MOV [DI], AL ; Move it to the current character in string 2 INC SI ; Move to the next character in string 1 INC DI ; Move to the next character in string 2 DEC CX ; Decrease the count for loop JNZ BEGINLOOP ; Continue to loop if count is not 0 MOV AH, 09H LEA DX, STRING2 int 21H ; Display String 2 MAINENDP;End of procedure END MAIN;End of program CODESEG ENDS

Result

Repetitive move instructions DEC CX ZF = 1 if CX = 0 JNZ LABEL if ZF = 0 then jump to the label

Addressing mode Register addressing: E.g ADD AX, BX fastest type of operations Immediate addressing Immediate contains a constant value or an expression E.g: MOV AX, 0245H Direct memory addressing One of operand references a memory location and the other operand references a register E.G MOV FLDF, AX

Addressing mode Direct-Offset addressing use arithmetic instruction to modify an address e.gMOV CX, DATAZ+2 Indirect memory addressing UseBX and BP, DI and SI within [ ] e.g. MOV [BX], CL

Addressing mode Base Displacement Addressing Uses BX, BP and DI, SI and combine with a displacement to form an effective address E.g MOV AL,[SI+2] Base-Index Addressing Combine BX,BP with DI,SI to form effective address E.G MOV AL,[BX+SI]

Addressing mode Base-Index Displacement Addressing Combine BX, BP and DI, SI and a displacement to form an effective address E.g MOV AL,[BX+SI+2]

NEAR and FAR address NEAR address consists of 16 bit offset portion of an address used in real mode FAR address consists of both the segment and offset portions in the form of 32 bit segment:offset

CMP Instruction [label:] CMP register/memory, register/memory/immediate Compares the first to the second operand Affects: AF, CF, OF, PF, SF and ZF flag CMP AX, DX JE Startloop

Conditional Jump instructions Jump based on unsigned data [label:] JE/JZshort-address Jump if equal or Jump if zero [label:] JNE/JNZshort-address Jump if not equal or Jump if not zero Flag: ZF

Example MOV AL, 5 CMP AL, 5 JE label1 JMP exit label1: MOV CX, BX exit: …..

Conditional Jump instructions JG: Jump if first operand is Greater then second operand (as set by CMP instruction). Signed. if (ZF = 0) and (SF = OF) then jump Syntax: [label:] JGshort-address

Example MOV AL, 5 CMP AL, -5 JG label1 JMP exit label1: MOV CX, -5 ; in this case AL > -5 exit:

Conditional Jump Instruction JL: Jump if first operand is Less then second operand (as set by CMP instruction). Signed. if SF <> OF then jump Syntax: [label:] JLshort-address

Example MOV AL, -2 CMP AL, 5 JL label1 JMP exit label1: MOV CX, 5; in this case AL < 5 exit: …