LAB 3: Programming in Assembly Language

Similar documents
INTERNATIONAL ISLAMIC UNIVERSITY OF MALAYSIA Kulliyyah Of Engineering Department Of Electrical Engineering

SORTING OF AN ARRAY USING 8086 MICROPROCESSOR

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

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

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.

Lecture 8: Control Structures. Comparing Values. Flags Set by CMP. Example. What can we compare? CMP Examples

Summer 2003 Lecture 11 06/25/03

Selection and Iteration. Chapter 7 S. Dandamudi

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

FACULTY OF ENGINEERING LAB SHEET

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

Basic Assembly Instructions

Chapter Four Instructions Set

Chapter Three Addressing Mode MOV AX, BX

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

Lab 6: Conditional Processing

IFE: Course in Low Level Programing. Lecture 6

Philadelphia University Student Name: Student Number:

16.317: Microprocessor Systems Design I Fall 2013

FACULTY OF ENGINEERING LAB SHEET

Assembly Language LAB

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

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

9/25/ Software & Hardware Architecture

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

ECpE 185 Laboratory Hand Assembly Fall 2006

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

Lab 3. The Art of Assembly Language (II)

Experiment 3 3 Basic Input Output

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

Babu Madhav Institute of Information Technology, UTU

CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY COMMUNICATION ENGINEERING REG 2008 TWO MARKS QUESTION AND ANSWERS

US06CCSC04: Introduction to Microprocessors and Assembly Language UNIT 3: Assembly Language Instructions II

Chapter 6 (Part a) Conditional Processing

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

ORG ; TWO. Assembly Language Programming

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

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

Microprocessor I, Spring 2007 Lab 2: Assembling and executing instructions with DEBUG software Due on 03/02/2007, 12:30pm EST

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

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

Assembly Language Programming of 8085

Intel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control.

Arithmetic and Logic Instructions And Programs

Assembly Language Programming of 8085

16.317: Microprocessor Systems Design I Fall 2014

Intel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control.

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

Q1: Multiple choice / 20 Q2: Data transfers and memory addressing

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

CSC 8400: Computer Systems. Machine-Level Representation of Programs

E CpE185 Laboratory Fall Introduction to Debug

16.317: Microprocessor Systems Design I Spring 2015

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 8. Conditional Processing

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

EXPERIMENT 1. FAMILIARITY WITH DEBUG, x86 REGISTERS and MACHINE INSTRUCTIONS

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.

Section 001. Read this before starting!

ADVANCE MICROPROCESSOR & INTERFACING

Practical Malware Analysis

Summer 2003 Lecture 4 06/14/03

3.0 Instruction Set. 3.1 Overview

Administration CS 412/413. Instruction ordering issues. Simplified architecture model. Examples. Impact of instruction ordering

Week /8086 Microprocessor Programming I

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

UNIT 1 REFERENCE 1 PREPARED BY S.RAVINDRAKUMAR, LECT/ECE, CHETTINAD COLLEGE OF ENGG AND TECH, KARUR

Lecture 5 Program Logic and Control

IBM PC Hardware CPU 8088, Pentium... ALU (Arithmetic and Logic Unit) Registers. CU (Control Unit) IP.

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

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

Philadelphia University Student Name: Student Number:

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

mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut

Advanced Assembly, Branching, and Monitor Utilities

X86-NASM STANDARD COMMANDS. Comment your code with a semicolon (;)! The assembler won t read anything after it.

Real instruction set architectures. Part 2: a representative sample

The 80386SX Processor Bus and Real-Mode Instruction Set

PHY4635/5635 Spring Lecture 8: Program Control Instructions

Lecture 10 Return-oriented programming. Stephen Checkoway University of Illinois at Chicago Based on slides by Bailey, Brumley, and Miller

PESIT Bangalore South Campus

1. Introduction to Assembly Language

16.317: Microprocessor Systems Design I Fall 2015

Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A

CPU. Fall 2003 CSE 207 Digital Design Project #4 R0 R1 R2 R3 R4 R5 R6 R7 PC STATUS IR. Control Logic RAM MAR MDR. Internal Processor Bus

8086 Programming. Multiplication Instructions. Multiplication can be performed on signed and unsigned numbers.

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

Arithmetic Instructions

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

Module 4c: Pipelining

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

Assembly Language Lab #5

1. Microprocessor kit Key board 1 3 Power Supply +5 V dc 1

COMPUTER ENGINEERING DEPARTMENT

Lecture (08) x86 programming 7

Computer Architecture and System Software Lecture 07: Assembly Language Programming

4 Categories Of 8085 Instructions That Manipulate Data

CSCI516: Program 1 - October 11, 2010 The Program is due: October 25, 2010 in the beginning of the class

EE 314 Spring 2003 Microprocessor Systems

Computer Department Chapter 7. Created By: Eng. Ahmed M. Ayash Modified and Presented by: Eng. Eihab S. El-Radie. Chapter 7

PRACTICAL WORKBOOK. Department of Computer Engineering University of Lahore. Designed and Compiled by : Engineer Zahid Muneer. Batch.

Transcription:

INTERNATIONAL ISLAMIC UNIVERSITY OF MALAYSIA Kulliyyah Of Engineering Department Of Electrical Engineering ELECTRICAL AND COMPUTER ENGINEERING LAB II (ECE 2202) Name: Matric Number: Group: Section: Date: Due Date: Instructor: LAB 3: Programming in Assembly Language Objective 1. Implementing IF_ELSE Statement In Assembly Language 2. Discuss more Instruction Sets with more interesting programs.

Background In previous lab, you have been introduced to some basic instructions of Intel Instruction Set and few small programs on how to use those commands. In today s lab, we will explore more Instruction Set with some simple tricky problems. Jump instructions are used to alter the execution path of instruction in your program. In 8088, the code segment register and instruction pointer are used to keep track the next instruction to be fetched for execution. There for, jump instruction will alter these two registers. You have seen JMP instructions last week. JMP means jump and it has no condition for performing the jump. This is known as unconditional jump. As opposite to this unconditional jump, there is conditional jump, which is characterized by instructions such as JNZ, JNBE and many more. Compare these two instructions: JMP 0FFF means jump to address 0FFF (h) JNZ 0FFF JUMP NOT ZERO means if the previous instruction result was not zero, then jump to address 0FFF (h). Else if the result is zero (condition is not met ) then proceed with next line. [ Note : There are 31 conditional jump instructions provided in 8088 microprocessor ] Also in previous lab, you have seen the LOOP instruction. The LOOP checks CX. If CX is 0, the processor proceeds to the next instruction. Otherwise, it decreases CX by 1, and then jumps to the address specified in the LOOP instruction. The same process can be also simulated using the JNZ instruction. For example: Mov cx,10 ** ------ dec cx jnz ** This is equivalent to: Mov cx,10 ** ------ loop ** New Assembly Language Instructions CMP AX,DX Subtracts DX from AX (AX-DX), but does not store the result. Instead it sets some flags. JNBE 200 JUMP NOT BELOW NOR EQUAL If the previous instruction (for example, CMP AX, DX) resulted in a positive value, then jump to the instructions at address 200. IF ELSE Since CMP is a subtraction operation, we can follow CMP with a conditional jump instruction to implement the IF-ELSE statement. We also can implement WHILE DO loop programs as we will see later.

Step 1 LOOP and JNZ In Background above find the programs, which shows you about JNZ and replace the ------ with inc bx. Rewrite those programs and explain the flow of those programs. (You are not required to run the program). If the inc ax is to repeated with inc cx, what do you think will happen? Step 2: CMP and JNBE NEXT Mov ax, value1 Mov bx, value2 Mov cx,1 Cmp ax,bx Jnbe NEXT Dec cx inc cx [ Note : You can count the address NEXT. The jump instruction takes 2 memories, and DEC takes 1] Test the above program for 1. ax > bx 2. ax < bx. In the above program, AX is compared to BX. If JNBE evaluates to true, only INC CX will be executed, and the value of CX will be 2. If JNBE is false, both DEC CX and INC CX will be executed, and the value of CX will be 1. 3.Now with the values of ax < bx, reverse the CMP instruction. What you observe? Explain the results for Step 2. Which part of the program resembles IF ELSE statement

Step 3: Arithmetic sum By using instruction LOOP; write a program that computes the sum of the numbers from 1 to 10h. Draw a flow chart before you program. Step 4 Write a program that counts the number of times a certain number appears in a range of memory. (Hint: to compare two numbers, subtract the two numbers. If the numbers are equal, the subtraction result will be zero. Then you can use JNZ.)

Questions: 1. What are flags? How many flags are available in 8088? 2. In CMP instructions, which flags are effected? 3. How can we implement While-Do loop by using CMP and jump instructions? 4. Describe the difference between a jump and call instructions. 5. The following program is known as delay loop. How many times does the JNZ DLY instruction get executed? Mov cx,100h DLY: Dec cx JNZ DLY Next:......