SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Similar documents
Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

Intel 8086: Instruction Set

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

8086 INSTRUCTION SET

ORG ; TWO. Assembly Language Programming

EC 333 Microprocessor and Interfacing Techniques (3+1)

db "Please enter up to 256 characters (press Enter Key to finish): ",0dh,0ah,'$'

CS-202 Microprocessor and Assembly Language

Kingdom of Saudi Arabia Ministry of Higher Education. Taif University. Faculty of Computers & Information Systems

Summer 2003 Lecture 4 06/14/03

CC411: Introduction To Microprocessors

ADVANCE MICROPROCESSOR & INTERFACING

CS/ECE/EEE/INSTR F241 MICROPROCESSOR PROGRAMMING & INTERFACING MODULE 4: 80X86 INSTRUCTION SET QUESTIONS ANUPAMA KR BITS, PILANI KK BIRLA GOA CAMPUS

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

9/25/ Software & Hardware Architecture

Q1: Define a character string named CO_NAME containing "Internet Services" as a constant?

SHEET-2 ANSWERS. [1] Rewrite Program 2-3 to transfer one word at a time instead of one byte.

CS499. Intel Architecture

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

EC 333 Microprocessor and Interfacing Techniques (3+1)

Week /8086 Microprocessor Programming II

.code. lea dx,msg2. Page 1/8. Problem 1: Programming in Assembly [25 Points]

Week /8086 Microprocessor Programming

Section 001 & 002. Read this before starting!

Week /8086 Microprocessor Programming I

EEM336 Microprocessors I. Data Movement Instructions

Arithmetic and Logic Instructions And Programs

BAHAR DÖNEMİ MİKROİŞLEMCİLER LAB4 FÖYÜ

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication

BLDEA S V.P. DR. P.G. HALAKATTI COLLEGE OF ENGINEERING & TECHNOLOGY, VIJAYAPURA

Code segment Stack segment

Chapter Four Instructions Set

Intel 8086 MICROPROCESSOR ARCHITECTURE

Lecture 16: Passing Parameters on the Stack. Push Examples. Pop Examples. CALL and RET

Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H.

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Q1: Multiple choice / 20 Q2: Protected mode memory accesses

Lecture (08) x86 programming 7

We will first study the basic instructions for doing multiplications and divisions

Section 001. Read this before starting!

Data Movement Instructions

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

PESIT Bangalore South Campus

BAHAR DÖNEMİ MİKROİŞLEMCİLER LAB3 FÖYÜ

COE 205 Lab Manual Experiment N o 12. Experiment N o Using the Mouse

CONTENTS. 1. Display a Message Display a one Digit Number Accept a Character from keyboard and display the character 4

3.1 DATA MOVEMENT INSTRUCTIONS 45

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

EC-333 Microprocessor and Interfacing Techniques

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Computer Architecture and System Software Lecture 06: Assembly Language Programming

Intel 8086 MICROPROCESSOR. By Y V S Murthy

Read this before starting!

Experiment 3 3 Basic Input Output

ASSEMBLY LANGUAGE PROGRAMMING OF THE MICROCOMPUTER

Signed number Arithmetic. Negative number is represented as

Basic Assembly SYSC-3006

Computer Architecture 1 ح 303

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

Arithmetic Instructions

UNIT 4. Modular Programming

The Stack. Lecture 15: The Stack. The Stack. Adding Elements. What is it? What is it used for?

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler:

UNIT III MICROPROCESSORS AND MICROCONTROLLERS MATERIAL OVERVIEW: Addressing Modes of Assembler Directives. Procedures and Macros

US06CCSC04: Introduction to Microprocessors and Assembly Language UNIT 1: Assembly Language Terms & Directives

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

8086 programming Control Flow Instructions and Program Structures

MICROPROCESSOR PROGRAMMING AND SYSTEM DESIGN

Chapter 3: Addressing Modes

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"


Section 002. Read this before starting!

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

CS401 Assembly Language Solved Subjective MAY 03,2012 From Midterm Papers. MC

COMPUTER ENGINEERING DEPARTMENT

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

PHY4635/5635 Spring Lecture 8: Program Control Instructions

Programming in Assembler. Laboratory manual. Exercise 3

Topics Introduction to Microprocessors. Chapter 5 Macros and modules. What is macro? How to use macro? (I) How to use macro?

Experiment #5. Using BIOS Services and DOS functions Part 1: Text-based Graphics

Module 3 Instruction Set Architecture (ISA)

1-Operand instruction types 1 INC/ DEC/ NOT/NEG R/M. 2 PUSH/ POP R16/M16/SR/F 2 x ( ) = 74 opcodes 3 MUL/ IMUL/ DIV/ DIV R/M

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

Computer Architecture and System Software Lecture 07: Assembly Language Programming

Mr. Sapan Naik 1. Babu Madhav Institute of Information Technology, UTU

PESIT Bangalore South Campus

Experiment 8 8 Subroutine Handling Instructions and Macros

TUTORIAL. Emulador Emu8086 do. Microprocessador 8086

8088/8086 Programming Integer Instructions and Computations

Assembly Language. Dr. Esam Al_Qaralleh CE Department Princess Sumaya University for Technology. Overview of Assembly Language

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

Computer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine

Basic Execution Environment

THE UNIVERSITY OF TRINIDAD & TOBAGO

CS401 Assembly Language Solved MCQS From Midterm Papers

8086 INTERNAL ARCHITECTURE

Introduction to Microprocessor

Transcription:

BACKGROUND Segment The "SEGMENT" and "ENDS" directives indicate to the assembler the beginning and ending of a segment and have the following format label SEGMENT [options] ;place the statements belonging to this segment here label ENDS The [options] field gives important information to the assembler for organizing the segment, but is not required. The ENDS label must be the same label as in the SEGMENT directive. In the full segment definition, the ".MODEL" directive is not used. Further, the directives ".STACK", ".DATA", and ".CODE" are replaced by SEGMENT and ENDS directives that surround each segment. The Assembly Programming Language consists of three types of segments Code segment contains the program code (instructions, commands) Stack segment is used to temporarily store information. Data segment is used to store the data (information) to be processed by the program Logical and Physical Address Physical Address is the 20-bit address that actually put on the address bus. (in 8086) Has a range of 00000H FFFFFH Offset Address is a location within 64K byte segment range Has a range of 0000H FFFFH Logical Address consists of segment address and offset address. Addressing in Code segment 8086 fetches the instructions from the code segment in order to execute a program. The logical address of an instruction consists of CS (Code Segment) and IP(instruction pointer) Physical Address is generated by shifting the CS one hex digit to the left and adding IP. Example CSIP is 250095F3H Start with CS 2500 Shift left CS 25000 Add IP 2E5F3 (25000+95F3) The microprocessor will retrieve the instruction in turn memory locations starting from 2E5F3.

Example If CS=24F6H and IP=634AH 2016-2017 SPRING TERM The logical address The offset address The physical address The lower range of the code segment The upper range of the code segment 24F6634A 634A 24F60+634A= 2B2AA 24F60000 => 24F60+0000 =24F60 24F6FFFF => 24F60+FFFF=34F5F Addressing in Data segment The area of memory allocated strictly for data is called data segment. Just as the code segment is associated with CS and IP as segment register and offset. The data segment uses DS and an offset value. In 8086 BX, SI and DI are used to hold the offset address. Example If DS= 7FA2H and the offset is 438EH The physical address The lower range of the data segment The upper range of the data segment Show the logical address 7FA20+438E= 83DAE 7FA20(7FA20+0000) 8FA1F(7FA20+FFFF) 7FA2438E Subroutine A subroutine is a group of instructions that will be used repeatedly in different locations of the program. Rather than repeat the same instructions several times, they can be grouped into a subroutine that is called from the different locations. In Assembly language, a subroutine can exist anywhere in the code. However, it is customary to place subroutines separately from the main program. The CALL instruction is a special branch instruction and performs the following operations Push the contents of the PC on the top of the stack Update the stack pointer Branch to the target address specified by the instruction The URN instruction is a special branch instruction that performs the following operations Pop the return address from the top of the stack into the PC Update the stack pointer.

Assembler data directives 2016-2017 SPRING TERM All the assemblers designed for the 80x86 (8088, 8086, 80188, 80186, 80286, 80386, 80386SX, 80486, and Pentium) microprocessors have standardized the directives for data representation. The following are some of the data directives used by the 80x86 microprocessor and supported by all software and hardware vendors of IBM PCs and compatibles. ORG Origin DB Define Byte DUP Duplicate DW Define Word EQU Equate DD Define Doubleword DQ Define Quadword DT Define Ten Bytes ORG is used to indicate the beginning of the offset address. It allows allocation of memory in byte-sized chunks. DUP is used to duplicate a given number of characters. This can avoid a lot of typing. DW is used to allocate memory 2 bytes (one word) at a time. This is used to define a constant without occupying a memory location. The DD directive is used to allocate memory locations that are 4 bytes (two words) in size. DQ is used to allocate memory 8 bytes (four words) in size. DT is used for memory allocation of packed BCD numbers. Instruction Operand(s) Description Load Effective Address. REG = address of memory (offset) LEA LDS REG,memory REG,memory MOV BX, 35h MOV DI, 12h LEA SI, [BX+DI]; SI = 35h + 12h = 47h The integrated 8086 assembler automatically replaces LEA with a more efficient MOV where possible. org 100h LEA AX, m ; AX = offset of m m dw 1234h END Load memory double word into word register and DS. REG = first word DS = second Word ORG 100h LDS AX, m m DD 12345678h END

Load memory double word into Word register and ES. REG = first word ES = second Word LES XCHG XLATB LAHF SAHF POPF PUSHF REG,memory REG, memory memory, REG REG, REG No operands No operands No operands No operands No operands ORG 100h LES AX, m m DW 1234h DW 5678h END Exchange values of two operands. operand1 operand2 MOV AL, 5 MOV AH, 2 XCHG AL, AH ; AL = 2, AH = 5 XCHG AL, AH ; AL = 5, AH = 2 Translate byte from table. Copy value of memory byte at DS[BX + unsigned AL] to AL register. AL = DS[BX + unsigned AL] ORG 100h LEA BX, dat MOV AL, 2 XLATB ; AL = 33h dat DB 11h, 22h, 33h, 44h, 55h Load AH from 8 low bits of Flags register. AH = flags register AH bit 7 6 5 4 3 2 1 0 [SF] [ZF] [0] [AF] [0] [PF] [1] [CF] bits 1, 3, 5 are reserved. Store AH from 8 low bits of Flags register. AH = flags register AH bit 7 6 5 4 3 2 1 0 [SF] [ZF] [0] [AF] [0] [PF] [1] [CF] bits 1, 3, 5 are reserved. Get flags register from the stack. flags = SS[SP] (top of the stack) SP = SP + 2 Store flags register in the stack. SP = SP 2 SS[SP] (top of the stack) = flags

Laboratory Preliminary Study 2016-2017 SPRING TERM Q1 The following program code separates the odd numbers and the even numbers of an array stored in memory. Please run the program step by step and observe its execution. org 0100h mov [0100h],'1' mov [0101h],'4' mov [0102h],'2' mov [0103h],'8' mov [0104h],'7' mov [0105h],'3' mov [0106h],'5' mov [0107h],'9' mov [0108h],'2' mov [0109h],'6' call PrintScreen mov bx,0100h mov cx,0109h mov dl,2 ; print original array ; first number ; last number ; divider OddNumberLoop mov si, bx mov al,[si] xor ah,ah div dl cmp ah,0 ; check the remainder jnz ContinueOddNumber jmp EvenNumberLoop ContinueOddNumber inc bx cmp bx,cx je Exit jmp OddNumberLoop EvenNumberLoop mov si,cx mov al,[si] xor ah,ah div dl cmp ah,0 jz ContinueEvenNumber jmp Swap ContinueEvenNumber dec cx cmp bx,cx

je Exit jmp EvenNumberLoop Swap push ax mov al,[bx] mov ah,[si] mov [bx],ah mov [si],al pop ax jmp OddNumberLoop Exit call PrintScreen hlt 2016-2017 SPRING TERM PrintScreen proc mov cx, 0 ; number of characters mov ah, 2 ; int 21, ah=2, print char to screen PrintLoop mov si,cx mov dl, [0100h+si] int 21h ; int 21, ah=2, print char to screen inc cx cmp cx,9 ja PrintExit mov dl, ',' int 21h ; int 21, ah=2, print char to screen jmp PrintLoop PrintExit mov dl, 0Dh ; return int 21h mov dl, 0Ah ; new line int 21h ret PrintScreen endp

Q2 The following program code calculates the sum of an array stored in memory. Please run the program step by step and observe its execution..model SMALL.STACK 100H.DATA PROMPT DB 'The Array elements are $' RESULT DB 0DH,0AH,'The Sum of the Array is = $' ARRAY DB 10,20,30,40,50,60,70,80,90,100.CODE MAIN PROC MOV AX, @DATA MOV DS, AX MOV BX, 10 LEA DX, PROMPT MOV AH, 9 MOV CX, BX LEA SI, ARRAY @LOOP XOR AH, AH MOV AL, [SI] CALL OUTDEC INC SI MOV AH, 2 MOV DL, 20H LOOP @LOOP LEA DX, RESULT MOV AH, 9 LEA SI, ARRAY CALL SUM CALL OUTDEC MOV AH, 4CH MAIN ENDP ; initialize DS ; set BX=10 ; load and display the string PROMPT ; set CX=BX ; set SI=offset address of ARRAY ; loop label ; clear AH ; set AX=[SI] ; call the procedure OUTDEC ; set SI=SI+1 ; set output function ; set DL=20H ; print a character ; jump to label @LOOP while CX!=0 ; load and display the string RESULT ; set SI=offset address of ARRAY ; call the procedure SUM ; call the procedure OUTDEC ; return control to DOS

SUM PROC ; this procedure will calculate the sum of an array ; input SI=offset address of the array ; BX=size of the array ; output AX=sum of the array PUSH CX ; push CX onto the STACK PUSH DX ; push DX onto the STACK XOR AX, AX ; clear AX XOR DX, DX ; clear DX MOV CX, BX ; set CX=BX @SUM ; loop label MOV DL, [SI] ; set DL=[SI] ADD AX, DX ; set AX=AX+DX INC SI ; set SI=SI+1 LOOP @SUM ; jump to label @SUM while CX!=0 POP DX ; pop a value from STACK into DX POP CX ; pop a value from STACK into CX ; return control to the calling procedure SUM ENDP ;******************************************************* OUTDEC PROC ; this procedure will display a decimal number ; input AX ; output none PUSH BX ; push BX onto the STACK PUSH CX ; push CX onto the STACK PUSH DX ; push DX onto the STACK CMP AX, 0 ; compare AX with 0 JGE @START ; jump to label @START if AX>=0 PUSH AX ; push AX onto the STACK MOV AH, 2 ; set output function MOV DL, "-" ; set DL='-' ; print the character POP AX ; pop a value from STACK into AX NEG AX ; take 2's complement of AX @START ; jump label XOR CX, CX ; clear CX MOV BX, 10 ; set BX=10 @OUTPUT ; loop label

XOR DX, DX DIV BX PUSH DX INC CX OR AX, AX JNE @OUTPUT MOV AH, 2 @DISPLAY POP DX OR DL, 30H LOOP @DISPLAY POP DX POP CX POP BX OUTDEC ENDP ; clear DX ; divide AX by BX ; push DX onto the STACK ; increment CX ; take OR of Ax with AX ; jump to label @OUTPUT if ZF=0 ; set output function ; loop label ; pop a value from STACK to DX ; convert decimal to ascii code ; print a character ; jump to label @DISPLAY if CX!=0 ; pop a value from STACK into DX ; pop a value from STACK into CX ; pop a value from STACK into BX ; return control to the calling procedure

Q3 Encode the following program code and write your observations about what is the main behavior of this program.

Q4 Write a procedure that exchanges the content of two 16-bit memory block. (Please don t use instruction XCHG). This procedure should have two input parameters which determine the physical addresses of the memory blocks to be swapped. It should be called in main procedure.