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

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.

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

ORG ; TWO. Assembly Language Programming

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

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

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

EC 333 Microprocessor and Interfacing Techniques (3+1)

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

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

Experiment 3 3 Basic Input Output

Code segment Stack segment

Chapter Four Instructions Set

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

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

Intel 8086: Instruction Set

EC-333 Microprocessor and Interfacing Techniques

PHY4635/5635 Spring Lecture 8: Program Control Instructions

8086 programming Control Flow Instructions and Program Structures

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

EC 333 Microprocessor and Interfacing Techniques (3+1)

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات

EEM336 Microprocessors I. Data Movement Instructions

Assignment no:4 on chapter no :3 : Instruction set of 8086

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

The x86 Architecture

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

8086 INTERNAL ARCHITECTURE

THE UNIVERSITY OF TRINIDAD & TOBAGO

Computer Architecture and System Software Lecture 07: Assembly Language Programming

Week /8086 Microprocessor Programming

PESIT Bangalore South Campus

ADVANCE MICROPROCESSOR & INTERFACING

CS-202 Microprocessor and Assembly Language

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

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

Lesson 1. Fundamentals of assembly language

9/25/ Software & Hardware Architecture

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

Computer Architecture and System Software Lecture 06: Assembly Language Programming

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

Module 3 Instruction Set Architecture (ISA)

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.

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

Lecture (08) x86 programming 7

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

Summer 2003 Lecture 4 06/14/03

Lecture 5:8086 Outline: 1. introduction 2. execution unit 3. bus interface unit

Program controlled semiconductor device (IC) which fetches (from memory), decodes and executes instructions.

Transfer of Control. Lecture 10 JMP. JMP Formats. Jump Loop Homework 3 Outputting prompts Reading single characters

Objectives. ICT106 Fundamentals of Computer Systems Topic 8. Procedures, Calling and Exit conventions, Run-time Stack Ref: Irvine, Ch 5 & 8

Experiment 8 8 Subroutine Handling Instructions and Macros

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

EC-333 Microprocessor and Interfacing Techniques

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

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

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

CC411: Introduction To Microprocessors

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

Parameter Passing. Procedure line. Calling procedure line. Most subroutines require parameters Can sometimes pass parameters via registers

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

Proposed Common Configuration Method

Chapter 3: Addressing Modes

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

Data Movement Instructions

Northern India Engineering College, Delhi (GGSIP University) PAPER I

1. Introduction to Assembly Language

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

Addressing Modes on the x86

Arithmetic Instructions

8086 INSTRUCTION SET

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

MICROPROCESSOR PROGRAMMING AND SYSTEM DESIGN

INDEX. 1 Study of intel 8085 micropeocessor kit. 2 Program to find addition of two 8 bit no. 3 Program to find subtraction of two 8 bit no.

Programming in Assembler. Laboratory manual. Exercise 3

CG2007 Microprocessor systems.

Basic characteristics & features of 8086 Microprocessor Dr. M. Hebaishy

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

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

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

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

Intel 8086 MICROPROCESSOR. By Y V S Murthy

16.317: Microprocessor Systems Design I Fall 2013

UNIT 4. Modular Programming

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

Assembly Language: g Part III. First Semester 2013 Department of Computer Science Faculty of Science Chiang Mai University

Week /8086 Microprocessor Programming I

Introduction to IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung

Intel 8086 MICROPROCESSOR ARCHITECTURE

Assembler Programming. Lecture 10

Hardware and Software Architecture. Chapter 2

Chapter 3. Assembly Language Programming with 8086

Objectives. Saving Interrupt Vectors. Writing a Custom Interrupt Handler. Examples of use of System functions for Input-Output and Interrupts

EE2007 Microprocessor systems.

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

Introduction to Microprocessor

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

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

CS499. Intel Architecture

WINTER 12 EXAMINATION Subject Code : Model Answer Page No : / N. a) Describe the function of SID and SOD pins of 8085 microprocessor

Transcription:

SHEET-2 ANSWERS [1] Rewrite Program 2-3 to transfer one word at a time instead of one byte. TITLE PROG2-3 PURPOSE: TRANSFER 6 WORDS OF DATA PAGE 60,132.MODEL SMALL.STACK 64.DATA ORG 10H DATA_IN DW 234DH, 1DE6H, 3BC7H, 566AH, 7890H, 8976H ORG 30H COPY DW 6 DUP(?).CODE MAIN PROC FAR MOV AX, @DATA MOV DS, AX MOV SI, OFFSET DATA_IN ;SI points to data to be copied MOV DI, OFFSET COPY ;DI points to copy of data MOV CX, 06 ;set up loop counter CX=6 MOV_LOOP: MOV AX, [SI] ;move the next word to AX MOV [DI], AX ;copy the word in AX to COPY area INC SI INC SI ;increment SI twice to point to next word ;increment DI twice to point to next position DEC CX ;decrement the counter JNZ MOV_LOOP ;jump if counter not zero MOV AH,4CH INT 21H MAIN ENDP END MAIN [2] Circle one: The linking process comes (after, before) assembling. Prepared By: Samsad Beagum, Lecturer, Department of CS and IT, Taif University. Page 1

The linking process comes after assembling. [3] In some applications it is common practice to save all registers at the beginning of a subroutine. Assume that SP = 1288H before a subroutine CALL. Show the contents of the stack pointer and the exact memory contents of the stack after PUSHF for the following: 1132:0450 CALL PROC1 1132:0453 INC BX PROC1 PROC PUSH AX PUSH BX PUSH CX PUSH DX PUSH SI PUSH Dl PUSHF PROC1 ENDP Prepared By: Samsad Beagum, Lecturer, Department of CS and IT, Taif University. Page 2

(Assume PROC1 is a NEAR procedure). The stack contents after executing PUSHF: SS:1278 SS:1279 SS:127A SS:127B SS:127C SS:127D SS:127E SS:127F SS:1280 SS:1281 SS:1282 SS:1283 SS:1284 SS:1285 SS:1286 SS:1287 SS:1288 Flags(L) Flags(H) DI(L) DI(H) SI(L) SI(H) DL DH CL CH BL BH AL AH 53 04 Low order byte of the flag register. High order byte of the flag register. Low order byte of the DI register. High order byte of the DI register. Low order byte of the SI register. High order byte of the SI register. Low order byte of the DX register. High order byte of the DX register. Low order byte of the CX register. High order byte of the CX register. Low order byte of the BX register. High order byte of the BX register. Low order byte of the AX register. High order byte of the AX register. IP for the INC instruction.(low byte) IP for the INC instruction(high byte) Start of Stack. [4] To restore the original information inside the CPU at the end of a CALL to a subroutine, the sequence of POP instructions must follow a certain order. Write the sequence of POP instructions that will restore the information in Problem 3. At each point, show the contents of the SP. Prepared By: Samsad Beagum, Lecturer, Department of CS and IT, Taif University. Page 3

The number of PUSH and POP instructions must match. The sequence of POP instructions: Initially, SP = 1278 POPF POP DI POP SI SP = 127A SP = 127C SP = 127E POP DX SP = 1280 POP CX SP = 1282 POP BX SP = 1284 POP AX SP = 1286 [5] In a FAR CALL, and are saved on the stack, whereas in a NEAR CALL, is saved on the stack. In a FAR CALL, CS and IP are saved on the stack, whereas in a NEAR CALL, IP is saved on the stack. [6] Compare the number of bytes of stack taken due to NEAR and FAR CALLs. NEAR CALL takes 2 bytes of stack to save the IP. FAR CALL takes 4 bytes of stack to save the CS and IP. [7] Find the contents of the stack and stack pointer after execution of the CALL instruction shown next. Prepared By: Samsad Beagum, Lecturer, Department of CS and IT, Taif University. Page 4

CS :IP 2450:673A CALL SUM 2450:673D DEC AH SUM is a near procedure. Assume the value SS: 1296 right before the execution of CALL. A near CALL saves only the contents of IP on the stack before calling a procedure. SS:1294 SS:1295 SS:1296 3D 67 IP address of the DEC instruction (Low order byte). IP address of the DEC instruction (High order byte). Start of Stack before executing CALL SUM. [8] The following is a section of BIOS of the IBM PC which is described in detail in Chapter 3. All the jumps below are short jumps, meaning that the labels are in the range -128 to+127. IP Code E06C 733F JNC ERROR1.. E072 7139 JNO ERROR1.. E08C 8ED8 C8: MOV DS, AX.. EOA7 EBE3 JMP C8.. EOAD F4 ERROR1: HLT Verify the address calculations of: (a) JNC ERROR1 (b) JNO ERROR1 (c) JMP C8 Prepared By: Samsad Beagum, Lecturer, Department of CS and IT, Taif University. Page 5

(Introduction: All conditional jumps are short jumps. (Short jumps - The address of the target (jumping location) should be within -128 to +127 bytes of the IP). So, short jumps are 2-byte instructions. 1st byte is the op-code of the jump, 2nd byte is the offset - a value between 00 and FF.) To find the target address, Target Address = Address of the instruction next to Jump + Second byte of the Jump instruction. (HOW THIS FORMULA WORKS FOR BACKWARD JUMP? In a backward jump, the second byte is the 2's complement of the offset. So when it is added to the address of the instruction next to Jump, we get the subtracted result - which is an address at the back). a) JNC ERROR1 Address of the instruction next to JNC = E06C+2 = E06E Second byte of the JNC instruction = 3F E06C 733F JNC ERROR1 Target Address (Address of ERROR1: HLT) = E06E + 3F = E0AD b) JNO ERROR1 Address of the instruction next to JNO = E072+2 = E074 Second byte of the JNO instruction = 39 E072 7139 JNO ERROR1 Prepared By: Samsad Beagum, Lecturer, Department of CS and IT, Taif University. Page 6

Target Address (Address of ERROR1: HLT) = E074 + 39 = E0AD c) JMP C8 Address of the instruction next to JMP C8 = E0A7+2 = E0A9 Second byte of the JMP C8 instruction = E3. EOA7 EBE3 JMP C8 Target Address (Address of C8: MOV DS, AX) = E0A9 + E3 = E08C (dropping the carry). [ Note: Second byte = E08C E0A9 = -1D 2 complement of 1D = E3 ] [9] The following program contains some errors. Fix the errors and make the program run correctly. Verify it through the DEBUG program. This program adds four words and saves the result. TITLE PROBLEM (EXE) PROBLEM 16 PROGRAM PAGE 60,132.MODEL SMALL.STACK 32.DATA DATA DW 234DH, DE6H, 3BC7H, 566AH ORG 10H Prepared By: Samsad Beagum, Lecturer, Department of CS and IT, Taif University. Page 7

SUM DW?.CODE START: PROC FAR MOV AX, DATA MOV DS, AX MOV CX, 04 MOV BX, 0 MOV DI, OFFSET DATA ;set up loop counter CX=4 ;initialize BX to zero ;set up data pointer BX LOOP1: ADD BX, [DI] ;add contents pointed at [DL] to BX JNZ LOOP1 MOV SI, OFFSET RESULT MOV [SI],BX ;increment DI ;jump if counter not zero ;load pointer for result ;store the sum MOV AH,4CH INT 21H START ENDP END START TITLE PROBLEM (EXE) PROBLEM 16 PROGRAM PAGE 60,132.MODEL SMALL.STACK 32.DATA DAT DW 234DH, 1DE6H, 3BC7H, 566AH Prepared By: Samsad Beagum, Lecturer, Department of CS and IT, Taif University. Page 8

ORG 10H SUM DW?.CODE START PROC FAR MOV AX, @DATA MOV DS, AX MOV CX, 04 MOV BX, 0 MOV DI, OFFSET DAT LOOP1: ADD BX, [DI] DEC CX JNZ LOOP1 MOV SI, OFFSET SUM MOV [SI],BX MOV AH,4CH INT 21H START ENDP END START ;set up loop counter CX=4 ;initialize BX to zero ;set up data pointer BX ;add contents pointed at [DL] to BX ;increment DI ;increment DI ;decrement the counter ;jump if counter not zero ;load pointer for result ;store the sum Prepared By: Samsad Beagum, Lecturer, Department of CS and IT, Taif University. Page 9