1 Using the Assembler Chapter – 4(A). 2 Exchanging Two Variables title Exchange Two Variables (Exchange.asm).model small.stack 100h.data value1 db 0Ah.

Slides:



Advertisements
Similar presentations
Chapter 2 (cont.) An Introduction to the 80x86 Microprocessor Family Objectives: The different addressing modes and instruction types available The usefulness.
Advertisements

1 Assembly Instructions Assembly language instructions may involve mnemonics, labels, variables, constants, and directives. Examples are as follows. here.
Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents.
ICS312 Set 6 Operands. Basic Operand Types (1) Register Operands. An operand that refers to a register. MOV AX, BX ; moves contents of register BX to.
Department of Computer Science and Software Engineering
1/2002JNM1 AL 00 Immediate Addressing Mode Mov AL, 3CH AL 3C.
Chapter 3 Addressing Modes
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.
Irvine, Kip R. Assembly Language For Intel-Based Computers TYPE and SIZE Operators TYPE –returns the size, in bytes of a single element of a data label.
Lect 3: Instruction Set and Addressing Modes. 386 Instruction Set (3.4) –Basic Instruction Set : 8086/8088 instruction set –Extended Instruction Set :
Memory model ModelDescription SMALLCode in one segment Data in one segment MEDIUMCode in > 1 segment Data in one segment COMPACTCode in one segment Data.
1 Using the Assembler Chapter 4 n Operators and Expressions n JMP and LOOP Instructions n Indirect Addressing n Using a Link Library.
The 8086 Assembly Programming Data Allocation & Addressing Modes
1 Lecture 4: Data Transfer, Addressing, and Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Target Processor Directives , When using.386, the program can only run on 386 and above processors.
Irvine: Assembly Language for Intel-Based Computers (1999) Symbolic Constants Equal-sign Directive EQU Directive TEXTEQU Directive.
CS2422 Assembly Language & System Programming October 3, 2006.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language Advantages 1. It reveals the secret of your computer’s hardware and software. 2. Speed. 3. Some special applications and occasions. Disadvantages.
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
Irvine, Kip R. Assembly Language For Intel-Based Computers.data string db "This is a string." COUNT = ($–string) ; calculate string length.code mov cx,COUNT.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
Lect 4: Instruction Set and Addressing Modes. 386 Instruction Set (3.4)  Basic Instruction Set : 8086/8088 instruction set  Extended Instruction Set.
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
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.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
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.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
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.
EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.
In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h.
Review of Assembly language. Recalling main concepts.
Fall 2012 Chapter 4: Data Transfers, Addressing, and Arithmetic.
MOV Instruction MOV destination,source  MOV AX,BX  MOV SUM,EAX  MOV EDX,ARRAY[EBX][ESI]  MOV CL,5  MOV DL,[BX]
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Assembly language programming
Instruction set Architecture
Introduction to assembly programmıng language
Format of Assembly language
Presentation on Real Mode Memory Addressing
Data Transfers, Addressing, and Arithmetic
Microprocessor Systems Design I
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
Assembly IA-32.
Symbolic Instruction and Addressing
Chapter 4: Instructions
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Data-Related Operators and Directives
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)
The Microprocessor & Its Architecture
Symbolic Instruction and Addressing
Computer Architecture CST 250
Assembler Directives end label end of program, label is entry point
Chapter 6 –Symbolic Instruction and Addressing
The JUMP GROUP Unconditional Jump (JMP).
Introduction to 8086 Assembly Language
Presentation transcript:

1 Using the Assembler Chapter – 4(A)

2 Exchanging Two Variables title Exchange Two Variables (Exchange.asm).model small.stack 100h.data value1 db 0Ah value2 db 14h.code main proc mov ; initialize DS register mov ds,ax mov al,value1 ; load the AL register xchg value2,al ; exchange AL and value2 mov value1,al ; store new value of AL mov ax,4C00h ; exit program int 21h main endp end main

3 Exchange Two Variables (Exchange.asm) 0000.model small 0000.stack 100h 0000.code 0000main proc 0000 B Rmov ; initialize DS register E D8mov ds,ax 0005 A Rmov al,value1 ; load the AL register Rxchg al,value2 ; exchange AL and value2 000C A Rmov value1,al ; store new value of AL 000F B8 4C00mov ax,4C00h ; return to DOS 0012 CD 21int 21h 0014main endp 0014.data Avalue1 db 0Ah value2 db 14h end main Source Listing File

4 Map File StartStop LengthNameClass 00000H 00012H 00013H _TEXTCODE 00014H 00015H 00002H _DATA DATA 00020H 0011FH 00100H STACK STACK Program entry point at 0000:0000

5 Overlapping Segments StartStopLength Name Class _TEXT CODE F00010 _DATA DATA F00100 STACK STACK Program entry point at 0000:0000

6 Memory Models

7 Target Processor Directives

8 OFFSET Directives OFFSET returns the 16-bit address (offset) of a label..data;say variable “bytes” located at offset 0000 bytesdb10h,20h,30h,40h wordsdw1000h,2000h,3000h.code mov di,offset bytes;DI = movax, offset bytes +1;AX = movsi, offset words +2;SI =

9 PTR Directives PTR is used to: 1-overrides the default size of an operand. 2- make clear the operand size..data val32dd h.code movax, val32;get low word (error) movbx, val32+2;get high word (error) movax, word ptr val32;AX = 5678h movbx, word ptr val32+2;BX = 1234h

10 PTR Directives PTR is used to: 1-overrides the default size of an operand.. 2-To make clear the operand size. Inc[bx];operand must have ;size (error message) inc byte ptr [bx];operand size made ;clear

11.data myByte db 1,2,3,4 myWord dw 1000h,2000h,3000h myDouble dd h.code mov ax,TYPE myByte ; 1 mov ax,TYPE myWord ; 2 mov ax,TYPE myDouble ; 4 TYPE Returns the size, in bytes of a single element of a data name (variable)

12.data myByte db 20 dup(?) myWord dw 5 dup(0).code mov ax,LENGTH myByte ; 20 mov ax,LENGTH myWord ; 5 LENGTH Returns a count of the number of individual elements in a data label that uses the DUP operator:

13.data myByte db 20 dup(?) myWord dw 5 dup(0).code mov ax,SIZE myByte ; 20 (20 * 1) mov ax,SIZE myWord ; 10 (5 * 2) SIZE Returns TYPE multiplied by LENGTH:

14 OperatorLevelDescription ( ) 1Parentheses +, - 2Positive and negative signs *, /,MOD 3Multiplication, Division +, - 4Addition, Subtraction Operator Precedence Table Property of associativity also applies

15 JMP and LOOP Instructions JMP is an unconditional jump to a code label LOOP creates a counting loop, using CX as the default counter

16 JMP: Distance Modifiers –JMP SHORT destination Jump within -128 to +127 bytes (an 8-bit value is added to IP) –JMP NEAR PTR destination Jump within same code segment. 16-bit offset is moved to IP) –JMP FAR PTR destination Jump to a different code code segment. Segment address moves to CS and Offset to IP.

17 JMP Example Label1:. jmp Label1 Unconditional Transfer of control to a label:

18 JMP Example.model small.stack 100h.data.code main proc mov mov ds,ax start:mov ah,2 mov dl,"A" int 21h jmp start mov ax,4c00h int 21h main endp end main

19 LOOP Instruction Automatically uses CX as the counter –decrements it automatically If CX > 0, LOOP transfers control to a label –otherwise, execution drops through

20 mov cx,3 ; loop counter mov bx,1 ; value to be added mov ax,0 ; holds the sum L1: add ax,bx inc bx Loop L1 LOOP Example AX= BX=CX=0000

21.model small.stack 100h.data.code main proc mov mov ds,ax mov cx,26 mov dl,41h NextChar:mov ah,02h int 21h inc dl loop NextChar mov ax,4c00h int 21h main endp end main LOOP Example inc cx mov cx, 0h

22 Indirect Addressing Indirect Operands An indirect operand is a register that contains the offset of a data in memory.  In 16 bit registers, SI, DI, BX and BP can be used as indirect operands.  Any 32 bit general purpose register can be used as indirect oprand (provided.386 or higher directive is used).

23 Indirect Addressing Indirect Operands [si], [di], [bx], [bp] Based and Indexed Operands array[si], array[di], array[bx] Base-Index Operands [bx+si], [bx+di] Base-Index with Displacement array[bx+si], array[bx+di]

24 Indirect Operand Example.data aString db "ABCDEFG“.code mov bx,offset aString add bx,5 mov dl,[bx]

25.data aList db 10h,20h,30h sum db 0.code mov bx,offset aList mov al,[bx] ; AL = 10h inc bx add al,[bx] ; AL = 30h inc bx add al,[bx] ; AL = 60h mov si,offset sum ; get offset of sum mov [si],al ; store the sum Adding 8-bit Integers mov bx, offset aList mov al,[bx] add al,[bx+1] add al,[bx+2] mov [bx+3],al

26.data wordList dw 1000h,2000h,3000h.code mov bx,offset wordList mov ax,[bx]; first number add ax,[bx+2]; second number add ax,[bx+4]; third number mov [bx+6],ax; store the sum Adding 16-bit Integers

27 Segments Defaults The offsets created by an operand is assumed to be from Data Segment, except when BP or EBP is part of an indirect operand. e.g., mov si, bp; both SI and BP become equal mov dl,[si]; looks for memory operand in Data Segment mov dl,[bp]; looks for memory operand in Stack Segment

28 Overriding the default Segments You can override the default segments also: mov al, cs:[si];offset from CS mov eax, es:[edi];offset from ES mov bx, fs:[edx];offset from FS mov dl, ss:[di];offset from SS mov ax, gs:[ecx];offset from GS mov dl, ds:[bp];offset from DS

29.data string db "This is a string." COUNT = ($–string).code mov cx,COUNT mov si,offset string L1: mov ah,2 mov dl,[si] int 21h inc si Loop L1 Displaying a String

30.data abc dw 0100h,0200h,0300h,0400h COUNT = ($ – abc) / (TYPE abc).code mov ax,0 mov di,offset abc mov cx,COUNT L1: add ax,[di] add di,TYPE abc Loop L1 Summing an Integer Array

31 Based and Indexed Operands The microsoft assembler permits the same address expression to be notated in various ways: Register Added to an Offset Register Added to a Constant mov dx,array[bx]mov ax,[bx + ROWVAL] mov dx,[di + array]mov dx,[bp+4] mov dx,[array+si]mov dx,2[si]

32 Based and Indexed Operands.data ROWSIZE = 5 array db 2h, 16h, 4h, 22h, 13h db 19h, 42h, 64h, 44h, 88h.code mov bx,ROWSIZE mov al,array[bx] ; AL = 19h Each row of this table contains five bytes. BX points to the beginning of the second row:

33 Based-Index Operands Add the value of a base register to an index register, producing an effective address of 0157: BX = 0155, SI = 0002 Example...

34.data ROWSIZE = 5 array db 10h, 20h, 30h, 40h, 50h db 60h, 70h, 80h, 90h,0A0h db 0B0h,0C0h,0D0h,0E0h,0F0h.code mov bx,offset array ; point to the array at 0150 add bx,ROWSIZE ; choose second row mov si,2 ; choose third column mov al,[bx + si] ; get the value at 0157 Base-Index Example

35 There is one important restriction in using Base- Idexed addressing i.e., you cannot combine two base registers or two index registers. Following statements are invalid: mov al,[bp+bx] mov al,[si+di] Base-Index Restriction

36 Base-Index with Displacement.data ROWSIZE = 5 array db 10h, 20h, 30h, 40h, 50h db 60h, 70h, 80h, 90h,0A0h db 0B0h,0C0h,0D0h,0E0h,0F0h.code mov bx,ROWSIZE ; row 1 mov si,2 ; column 2 mov dl,array[bx + si] ; DL = 80h

37 32-Bit Registers.386 mov ax,[ebx+3] mov dl,string[edx] mov ecx,[esi] mov ebx,[eax] The.386 directive permits any of the following registers to be used as indirect operands: EAX, EBX, ECX, EDX, ESI, EDI, EBP