1 Assembly Instructions Assembly language instructions may involve mnemonics, labels, variables, constants, and directives. Examples are as follows. here.

Slides:



Advertisements
Similar presentations
Assembly Programming Notes for Practical2 Munaf Sheikh
Advertisements

1 x86’s instruction sets. 2 Instruction Set Classification  Transfer Move  Arithmetic Add / Subtract Mul / Div, etc.  Control Jump Call / Return, etc.
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
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
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.
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.
Irvine: Assembly Language for Intel-Based Computers (1999) Symbolic Constants Equal-sign Directive EQU Directive TEXTEQU Directive.
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.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Assembly Language – Lab 5
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 ;
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.
Multiplication and Division Instructions & the 0Ah function.
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.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#9) By Dr. Syed Noman.
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
Lecture 9 (The Stack and Procedures). 1 Lecture Outline Introduction The Stack The PUSH Instruction The POP Instruction Terminology of Procedures INDEC.
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.
Microprocessors used in Personal Computers. The Memory Map of a Personal Computers Transient Program Area (TPA): Holds the operating system (interrupt.
Review of Assembly language. Recalling main concepts.
Irvine, Kip R. Assembly Language for Intel-Based Computers. Chapter 7: Integer Arithmetic Slides to Accompany Assembly Language for Intel-Based Computers,
ICS 312 SET 10 Multiplication & Division & input using function 0Ah.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
BITS Pilani Pilani Campus Pawan Sharma Lecture /12/ EEE /INSTR/CS F241 ES C263 Microprocessor Programming and Interfacing.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA 1 Assembly Language Programming.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
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.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Assembly language programming
Instruction set Architecture
Introduction to assembly programmıng language
Format of Assembly language
Data Transfers, Addressing, and Arithmetic
Microprocessor and Assembly Language
INSTRUCTION SET.
Microprocessor and Assembly Language
University of Gujrat Department of Computer Science
Morgan Kaufmann Publishers Computer Organization and Assembly Language
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
X86’s instruction sets.
Introduction to Assembly Language
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.
שפת סף וארכיטקטורה של מעבד 8086
Stack and Subroutines Module M17.1 Section 11.2.
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
Chapter 6 –Symbolic Instruction and Addressing
CNET 315 Microprocessor & Assembly Language
CSC 497/583 Advanced Topics in Computer Security
Introduction to 8086 Assembly Language
UNIT-II ADDRESSING MODES & Instruction set
(Array and Addressing Modes)
Presentation transcript:

1 Assembly Instructions Assembly language instructions may involve mnemonics, labels, variables, constants, and directives. Examples are as follows. here 1 mov 5 ax,23;set ax value msg 2 db 6 "help$" ;ASCII bytes assigned to msg var 3 db 6 10;var assigned a value of 10 num 4 equ 6 20;num has the value 20 _____________________________________________________________ 1 label 4 constant 2 variable of ASCII bytes 5 mnemonic 3 one-byte numeric variable 6 directive

2 Define Byte, Word Define Byte Variables (memory locations) Define Word Variables (memory locations)

3 Define Byte, Word list db10,20,30,40 will store the four values in consecutive locations. If the offset of list is 0000, they will be stored in 0000, 0001, 0002, 0003, respectively. list refers to 0000, list+1 refers to 0001, etc. Value1 dw 2AB6h will place two bytes in consecutive locations with the low order byte in the lower memory location as: B6 2A

4 Character or String Constants ‘ABC’ “This is a test.” ‘This is my file.’ Define a variable called message stored at offset 0000 for any of the above. For example: message db ‘ABC’. Then “B” of “ABC” is at offset 0001 and “i” of “This …” is at offset 2

5 Pointer Given: message db ‘ABC’;define 3 bytes P db message;P points to message The variable P contains the offset of message

6 ASCII Table

7 MOV Instruction Allowable MOVs with scratch registers MOV reg,reg MOV mem,reg MOV reg,mem MOV mem,immed MOV reg,immed Allowable MOVs with segment registers (except CS) MOV segreg,reg16 MOV segreg,mem16 MOV reg16,segreg MOV mem16,segreg

8 Direct Operands

9 Illegal Moves

Label Directive.data countB label byte;byte attribute, ;no storage allocated countw dw 0020h;word attribute.code mov al,countB;retrieve low byte of count mov cx,countW;retrieve all of count countB countW

11 Addressing Modes Addressing ModeExample Description Directmov ax,bx Effective address (EA) are the registers Register Indirectmov ax,[bx] EA is the contents of a register Basedmov ax,[bp + 1] EA is the sum of a base register and a displacement Indexedmov [di + 2],ax EA is the sum of an index register and a displacement Based Indexedmov ax,[bx + si] EA is the sum of a base register and an index register Based Indexed with mov ax,[bx + si + 2] EA is the sum of a base Displacement register, an index register and a displacement

12 Based Index Addressing Example Adding Bytes In the following example of based indexed addressing, the contents of 16d bytes beginning at ds:1000h and ending with ds:100Fh are accumulated in the al register. cs:100 mov al,0 ;initialize AL register cs:102 mov cx,10h;set loop counter to 10h=16d cs:105 mov si,0;set si=0 cs:108 mov bx,1000h ;set bx=1000h as offset address cs:10b add al,[bx + si] ;accum. contents of mem. loc. [bx+si] cs:10d inc si;increment si cs:11e1 loop 10bh;return to add

13 Based Index Addressing Example Adding Words In the following example of based indexed addressing, the contents of 16d words beginning at ds:1000h and ending with ds:101Dh are accumulated in the ax register. cs:100 mov ax,0 ;initialize AX register cs:103 mov cx,10h;set loop counter to 10h=16d cs:106 mov si,0;set si=0 cs:109 mov bx,1000h ;set bx=1000h as offset address cs:10c add ax,[bx + si] ;accum. contents of mem. loc. [bx+si] cs:10e add si,2;increment si by 2 cs:111 loop 10ch;return to add

14 Stack Operation To save register contents before calling a subroutine: ;save register contents before calling subroutine pushax pushbx pushcx pushdx ;restore register contents after returning from subroutine popdx popcx popbx popax

15 Assemble-Link-Execute Cycle.asm.obj.lst.exe.map MASM

16 Hello World.lst File title Hello World Program (hello.asm) ;This program displays "Hello, world!" directive ->.model small <- code and data each < 64K directive ->.stack 100h <- 256 bytes reserved 0000 directive ->.data C 6C 6F 2Cmessage db "Hello, world!",0dh,0ah,'$' F 72 6C D 0A directive ->.code 0000main proc <- begin procedure 0000 B R mov <- assigns seg. Addr E D8 mov ds,ax to DS 0005 B4 09 mov ah, BA 0000 R mov dx,offset message 000A CD 21 int 21h 000C B8 4C00 mov ax,4C00h 000F CD 21 int 21h 0011main endp <- end procdure end main <- end assembly

17 Hello World.map File Start Stop Length Name Class 00000H 00010H 00011H _TEXT CODE 00012H 00021H 00010H _DATA DATA 00030H 0012FH 00100H STACK STACK Origin Group 0001:0 DGROUP Program entry point at 0000:0000

18 XCHG Instruction Problem: move bx to ax and ax to bx mov cx,ax;ax stored temporarily in cx mov ax,bx;move bx to ax mov bx,cx;move cx (really ax) to bx or use: xchg ax,bx Allowed: xchg reg,reg xchg reg,mem xchg mem,reg

19 XCHGing Two Variables Cannot do: xchg mem1,mem2, but

20 Arithmetic Instructions INC and DEC Instructions inc destination;add 1 to destination dec destination;subtract 1 from destination where destination is reg or mem Examples: inc al dec ax dec byte ptr membyte;dec 8-bit memory operand dec memword;dec memory operand inc word ptr memword;inc 16-bit memory operand

21 Arithmetic Instructions ADD Instruction add destination, source Example: add ax,bx Contents of Registers Before After add ax,bx AX |0FFF |1000 | BX |0001 |0001 | add ax,bx AX |0002 |0001 | plus a BX |FFFF |FFFF | carry

22 Arithmetic Instructions ADD Instruction Consider the way in which add and adc, add with a carry, deal differently with the carry flag. Both the AX and BX registers contain 0000 and the carry flag is set, CY. add ax,bx yields AX=0, BX=0 and NC (no carry) adc ax,bx yields AX=1, BX=0 and NC

23 Arithmetic Instructions SUB Instruction sub destination, source Example: sub ax,bx Contents of Registers Before After sub ax,bx AX |00A0 |009F | BX |0001 |0001 | sub ax,bx AX |0005 |FFFF | BX |0006 |0006 |

24 Arithmetic Instructions MUL Instruction mul multiplier ;multiplicand in ax ;product in dx,ax Example: mul bx Contents of Registers Before After mul bx AX |FFFF |FFF0 | BX|0010 |0010 | DX|0000 |000F |

25 Arithmetic Instructions DIV Instruction div divisor ;dividend in dx,ax: quotient in ax ;remainder in dx Example: div bx Contents of Registers Before After div bx AX|FFF1 |FFFF | BX|0010 |0010 | DX|000F |0001 |

26 Memory Models Produces.com files What we will use Linear addressing

27 Overlapping Segments )