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

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

Programs for Assembly Language Programming

Week /8086 Microprocessor Programming I

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.

EC 333 Microprocessor and Interfacing Techniques (3+1)

Week /8086 Microprocessor Programming II

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

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

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

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Arithmetic Instructions

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

Experiment 3 3 Basic Input Output

UNIT 4. Modular Programming

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

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

8086 Assembly Language Programming

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

Lecture (08) x86 programming 7

Week /8086 Microprocessor Programming

Submitted To. Submitted By. Department Of Computer Science And Engineering. Dr. Md. Rabiul Islam. Name: Ashadullah Shawon.

Assembly Language Lab #5

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

Lecture (07) x86 programming 6

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

Arithmetic and Logic Instructions And Programs

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

Introduction to 8086 Assembly

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

Overview: 1. Overview: 2

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

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

CS-202 Microprocessor and Assembly Language

THE UNIVERSITY OF TRINIDAD & TOBAGO

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

LAB 3: Programming in Assembly Language

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

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

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

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

A4 Sample Solution Ch3

Assembly Language LAB

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

FACULTY OF ENGINEERING LAB SHEET

Instructions moving data

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

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

Assembler Programming. Lecture 8

EXPERIMENT TWELVE: USING DISK FILES

Experiment #2. Addressing Modes and Data Transfer using TASM

Intel 8086: Instruction Set

LAB 5 Arithmetic Operations Simple Calculator

EEM336 Microprocessors I. Data Movement Instructions

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

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

Signed number Arithmetic. Negative number is represented as

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

ADVANCE MICROPROCESSOR & INTERFACING

Computer Science Final Examination Wednesday December 13 th 2006

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide

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

Summer 2003 Lecture 4 06/14/03

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

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

PESIT Bangalore South Campus

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

Basic Assembly Instructions

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

Mnem. Meaning Format Operation Flags affected ADD Addition ADD D,S (D) (S)+(D) (CF) Carry ADC Add with ADC D,C (D) (S)+(D)+(CF) O,S,Z,A,P,C

5. Using Signed Numbers and Look-up Tables

8086 INSTRUCTION SET

ORG ; TWO. Assembly Language Programming

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

Assignment 3. Problem Definition:

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

FACULTY OF ENGINEERING LAB SHEET

Experiment 8 8 Subroutine Handling Instructions and Macros

Programming in Assembler. Laboratory manual. Exercise 3

Hands on Experience for Faculty in Laboratories Phase I JNTUK, Kakinada

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

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

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

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

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

Memory Organization. 27 December 2016 Pramod Ghimire. Slide 1 of 21

COMPUTER ENGINEERING DEPARTMENT

Chapter 3: Addressing Modes

Module 3 Instruction Set Architecture (ISA)

ICAL EN LAB MANUAL CS MICROPROCESSOR AND MICROCONTROLLER LABORATORY. Regulation. Branch. Year & Semester. Dharmapuri : B.E. CSE.

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Basic Assembly SYSC-3006


EXPERIMENT NINE DEVELOPING MACRO SEQUENCES

Video processing The INT instruction enables program to interrupt its own processing. Use INT instruction to handle inputs and outputs

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

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 13: 16-Bit MS-DOS Programming

Lesson 1. Fundamentals of assembly language

CS401 Assembly Language Solved MCQS From Midterm Papers

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

9/25/ Software & Hardware Architecture

Transcription:

University of Kashmir, North Campus Course Code Course Name Course Instructor MCA-104-DCE Assembly Language Programming Bilal Ahmad Dar CONTENTS 1. Display a Message 2 2. Display a one Digit Number 3 3. Accept a Character from keyboard and display the character 4 4. Addition of two 1 digit numbers 5 5. Subtraction of two 1 digit numbers 7 6. Multiplication of two 1 digit numbers 9 7. Division of two 1 digit numbers 11 8. Check whether a number is Even or Odd(one digit) 13 9. Check whether a number is Prime or not(one digit) 14 10. Find Factorial of a number (number<=6) 16 11. Check whether a string is Palindrome or not 19 1

Display a Message msg DB Hello World$" ; define memory model ; beginning of stack segment ; beginning of data segment ;message to be displayed ; $ is required (same as \0 in C) MOV DX, OFFSET MSG ; beginning of code segment ; start execution ; display message using 09h DOS function MOV AH, 09H END ; return to DOS ; end of file 2

Display a one Digit Number ; define memory model ; beginning of stack segment ; beginning of data segment Var DB 10 ;declare Var as data byte and initialize it with 10 ; beginning of code segment ; start execution MOV DL, Var ADD DL, 48 ; store 58 (ASCII of 10) in DL MOV AH, 02 ; Display 5 END ; return to DOS ; end of file 3

Accept a Character from keyboard and display the character MOV AH, 01H ; define memory model ; beginning of stack segment ; beginning of data segment ; beginning of code segment ; start execution ; accept a character from keyboard MOV DL, AL MOV AH, 02H ; move ASCII of character into DL ; Print the Character END ; return to DOS ; end of file 4

Addition of two 1 digit numbers TEN DB 10 Msg1 DB "Enter First Number:$" Msg2 DB " Enter second Number:$" Msg3 DB "SUM:$ MOV DX,OFFSET Msg1 ; Display message Enter first Number MOV AH,01H ; accept first number SUB AL,48 MOV BL,AL MOV DX,OFFSET Msg2 ; convert ASCII value of number into decimal ; Store first number in BL ; Display message Enter second Number MOV AH,01H ; accept second number SUB AL,48 MOV BH,AL ADD BL,BH MOV DL,10 ; convert ASCII value of number into decimal ; Store second number in BH ; BL = BL +BH ;Ascii value of newline 5

;display newline MOV DL,13 ;Ascii value of Carriage return ;display carriage return MOV DX,OFFSET Msg3 ; Display message Sum MOV AL, BL MOV AH,0H DIV TEN ; store result in AL ; clear AH ; divide result(al) with 10, after operation ; AL=quotient, AH= remainder MOV CL,AH CMP AL,0 JZ LAB MOV DL,AL ; store remainder in CL ;check if quotient = 0 then ; jump to label LAB ;display Ascii value of quotient if sum is 2 digit ADD DL,48 LAB: MOV DL,CL ;display AScii value of remainder ADD DL,48 END 6

Subtraction of two 1 digit numbers ;first number should be greater than second number Msg1 DB "Enter First Number:$" Msg2 DB " Enter Second Number:$" Msg3 DB "Difference:$" MOV DX, OFFSET Msg1 ; Display message Enter first Number MOV AH, 09H MOV AH, 01H ; accept first number SUB AL, 48 MOV BL, AL ; convert ASCII value of number into decimal ; Store first number in BL MOV DX, OFFSET Msg2 MOV AH, 09H ; Display message Enter second Number MOV AH, 01H ; accept second number SUB AL, 48 MOV BH,AL SUB BL,BH ; convert ASCII value of number into decimal ; Store second number in BH ; BL=BL-BH 7

MOV DL,10 ;Ascii value of newline ; print Newline MOV DL,13 ;Ascii value of Carriage return ; print carriage return MOV DX,OFFSET Msg3 ; Display message Difference MOV DL,BL ADD DL,48 MOV AH, 02H ; convert decimal value of result into ASCII ; display result END 8

Multiplication of two 1 digit numbers TEN DB 10 Msg1 DB "Enter First Number:$" Msg2 DB " Enter second Number:$" Msg3 DB "PRODUCT:$ MOV DX,OFFSET Msg1 ; Display message Enter first Number MOV AH,01H ; accept first number SUB AL,48 MOV BL,AL MOV DX,OFFSET Msg2 ; convert ASCII value of number into decimal ; Store first number in BL ; Display message Enter second Number MOV AH,01H ; accept second number SUB AL,48 MOV BH,AL MOV AL,BL MOV AH,0 MOV BL,BH ; convert ASCII value of number into decimal ; Store second number in BH ; multiplicand(8bit) must reside in AL for Multiplication ; clear AH ;move second number in BL 9

MOV BH,0 MUL BX MOV BX,AX MOV DL,10 ;clear BH ;AX=AX*BX ;move result in BX ;Ascii value of newline ;display newline MOV DL,13 ;Ascii value of Carriage return ;display carriage return MOV DX,OFFSET Msg3 ; Display message Product MOV AL, BL MOV AH,0H ; store result in AL ; clear AH DIV TEN ; divide result(al) with 10, after operation ; AL=quotient, AH= remainder MOV CL,AH CMP AL,0 JZ LAB MOV DL,AL ; store remainder in CL ;check if quotient = 0 then ; jump to label LAB ;display Ascii value of quotient if sum is 2 digit ADD DL,48 LAB: MOV DL,CL ;display AScii value of remainder ADD DL,48 END 10

Division of two 1 digit numbers TEN DB 10 Msg1 DB "Enter Dividend:$" Msg2 DB " Enter Divisor:$" Msg3 DB "Quotient:$ Msg4 DB Remainder:$ MOV DX,OFFSET Msg1 ; Display message Enter first Number MOV AH,01H ; accept first number SUB AL,48 MOV BL,AL MOV DX,OFFSET Msg2 ; convert ASCII value of number into decimal ; Store first number in BL ; Display message Enter second Number MOV AH,01H ; accept second number SUB AL,48 MOV BH,AL MOV AL,BL ; convert ASCII value of number into decimal ; Store second number in BH ; Dividend(8bit) must reside in AL for Division 11

MOV AH,0 DIV BH MOV BH,AH MOV BL, AL MOV DL,10 ; clear AH ; AL=quotient, AH= remainder ;move remainder in BH ; move quotient in BL ;Ascii value of newline ;display newline MOV DL,13 ;Ascii value of Carriage return ;display carriage return MOV DX,OFFSET Msg3 ; Display message Quotient MOV DL,BL ;display Ascii value of quotient ADD DL,48 MOV DX,OFFSET Msg4 ; Display message Quotient MOV DL,BH ;display AScii value of remainder ADD DL,48 END 12

Check whether a number is Even or Odd(one digit) Msg DB "Enter a Number$" EvenMsg DB "The number is Even$" OddMsg DB "The number is Odd$" MOV DX, offset Msg ; display message Enter a Number MOV AH, 09H MOV AH,01H ; accept a number SUB AL,48 MOV BL,2 DIV BL CMP AH,0 JNE odd MOV DX, offset EvenMsg ; convert ASCii of number into decimal ; move divisor in BL ; AL=quotient, AH= remainder ; check if remainder = 0 then ; jump to label odd ; display even message odd: MOV DX,offset OddMsg ; display odd message END 13

Check whether a number is Prime or not(one digit).model small MSG1 DB "NUMBER IS PRIME$" MSG2 DB "NUMBER IS NOT PRIME$" MSG DB "ENTER A NUMBER :$" A DB 2 MOV DX,OFFSET MSG ; Display message Enter a number MOV AH,01H ; accept a number SUB AL,48 MOV BL,AL CMP BL,1 ; convert ASCII value of number into decimal ; move number in BL ; if number is 1 jump to COMPO JZ COMPO CMP BL,0 ; if number is 0 exit JZ EXT MOV DL,10 ; display newline MOV AH,02 MOV DL,13 ; carriage return MOV AH,02 14

LAB: MOV AL,BL MOV AH,0 DIV A CMP AH,0 ; divide the number repeatedly by (2 to num) ; if number is divisible by A then jump to CHECK JZ CHECK INC A JMP LAB ; else increment A ; jump to start of the loop PRIME: MOV DX,OFFSET MSG1 ; display message prime JMP EXT ; exit CHECK: CMP BL, A ; if the number is divisible by itself jump to prime COMPO: JZ PRIME MOV DX,OFFSET MSG2 ; display message not prime EXT: END 15

Find Factorial of a number (number<=6) MSG1 DB "FACTORIAL IS:$" MSG2 DB "ENTER A NUMBER <=6:$" MSG3 DB "OUT OF ORDER$" C DB 10 ARY DB 4 DUP(?) MOV DX,OFFSET MSG2 MOV AH,09 MOV AH,01 SUB AL,48 MOV AH,00 CMP AX,1 JB EXITT CMP AX,6 JA EXITT MOV CX,AX MOV AX,1 LABE: MUL CX LOOP LABE 16

MOV CX,00H MOV SI,OFFSET ARY LABELL: DIV C MOV [SI],AH MOV AH,00 INC SI INC CX CMP AL,00 JNZ LABELL MOV DL,10 MOV AH,02 MOV DL,13 MOV AH,02 MOV DX,OFFSET MSG1 MOV AH,09 DEC SI LABEE: MOV DL,[SI] ADD DL,48 MOV AH,02 DEC SI LOOP LABEE 17

EXITT: JMP EXII MOV DL,10 MOV AH,02 MOV DL,13 MOV AH,02 MOV DX,OFFSET MSG3 MOV AH,09 EXII: END 18

Check whether a string is Palindrome or not MSG DB "ENTER A STRING$" BUF DB 10,0,10 DUP(0) YES DB 13,10," STRING IS PALINDROME$" NO DB 13,10,"STRING IS NOT PALINDROME$" FLAG DB? MOV DX,OFFSET MSG MOV AH,09 MOV DX, OFFSET BUF MOV AH,0AH MOV AL,[BUF+1] MOV BX,OFFSET BUF+2 MOV AH,0 ADD BX,AX MOV [BX],BYTE PTR '$' MOV AL,[BUF+1] MOV CL,2 DIV CL MOV CL,AL MOV CH,0 19

MOV AL,[BUF+1] MOV AH,0 MOV DI,OFFSET BUF+1 ADD DI,AX MOV SI,OFFSET BUF+2 LOGIC: CMP CX,0 JE DONE MOV [FLAG], 0H MOV AL,[SI] CMP AL,[DI] JNE DONE MOV [FLAG], 1 DEC CX INC SI DEC DI JMP LOGIC DONE: CMP [FLAG],0 JE NO_PL MOV DX,OFFSET YES NO_PL: MOV DX,OFFSET NO 20