Assembly Language programming (2)

Similar documents
TUTORIAL Assembly Language programming (2)

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

Microcontroller Intel [Instruction Set]

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

Programming of 8085 microprocessor and 8051 micro controller Study material

Assembly Language programming (3)

Principle and Interface Techniques of Microcontroller

8051 Microcontrollers

8051 Microcontroller

SN8F5000 Family Instruction Set


Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.

Microcontroller. Instruction set of 8051

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

8051 Programming: Arithmetic and Logic

8051 Overview and Instruction Set

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Arithmetic and Logic

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

Digital Blocks Semiconductor IP

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP

Q. Classify the instruction set of 8051 and list out the instructions in each type.

Module Contents of the Module Hours COs

Dragonchip. Instruction Set Manual

Dodatak. Skup instrukcija

8051 Microcontroller Logical Operations. Prepared by : A. B. Modi Target Audience : 5 th Semester Students

DR bit RISC Microcontroller. Instructions set details ver 3.10

Chapter 3. Bit Addressable Area. By DeccanRobots

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

Assembly Language programming (1)

Principle and Interface Techniques of Microcontroller

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

Instruction Set Of 8051

8051 Programming using Assembly

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

~: Simple Programs in 8051 assembly language :~

Lecture 5. EEE3410 Microcontroller Applications Department of Electrical Engineering Assembly Language Programming (1)

MICROPROCESSOR LABORATORY MANUAL

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000,

What Registers are available? Programming in Assembler. Assembler Programming - like early Basic. Assembler Data Movement Instructions

ENE 334 Microprocessors

8051 Microcontroller Assembly Programming

8051 Core Specification

8051 Addressing Modes

Assembly Language Programming of 8085

MCS -51 Programmer s Guide and Instruction Set

C51 Family. Architectural Overview of the C51 Family. Summary

UNIT-III ASSEMBLY LANGUAGE PROGRAMMING. The CPU can access data in various ways, which are called addressing modes

1. Write A Program to move a block of data within the internal RAM

80C51 family programmer s guide and instruction set. 80C51 Family. PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization. Philips Semiconductors

Assembly Language Programming of 8085

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO.

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

Figure Programming model

Embedded Controller Programming

ELEG3924 Microprocessor

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

MISSOURI UNIVERSITY OF SCIENCE & TECHNOLOGY. BCD Arithmetic. Implementing the Decimal Adjust Command in WIMP51 CpE-213 Sp 2014 Project 1 3/17/2014

Highlights. FP51 (FPGA based 1T 8051 core)

Y51 Microcontroller. Technical Manual

C51 Family. C51 Family Programmer s Guide and Instruction Set. Summary

Introduction To MCS-51

Application Brief D-005

The 8051 Microcontroller and Embedded Systems

Question Bank Microprocessor and Microcontroller

2. Write an 8051 program to generate a square wave of 25 khz at pin P2.3 using XTAL = 12 MHz. Solution:

Chapter Addressing Modes

Chapter Family Microcontrollers Instruction Set

CPEG300 Embedded System Design. Lecture 3 Memory

ELEG3924 Microprocessor

Chapter 9. Programming Framework

NAME as31 - An Intel 8031/8051 assembler. SYNOPSIS as31 [-h] [-l] [-s] [-v] [-Aarg] [-Ffmt] [-Ofile] infile.asm

Module I. Microcontroller can be classified on the basis of their bits processed like 8bit MC, 16bit MC.

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 9 Simple I/O Interfacing

Contents. Join the Technical Community Today!

Control Transfer Instructions Jump, Loop, and Call. ECE473/573 Microprocessor System Design, Dr. Shiue

AL8051S 8-BIT MICROCONTROLLER Application Notes

CS 320. Computer Architecture Core Architecture

JUMP, LOOP AND CALL INSTRUCTIONS

Assembly Language Programming Assignment 1

8051 Single Board Monitor Programming. Minmon - Yeralan & Ahluwalia. PaulMon1 & PaulMon2 - Paul Stoffregen

Chapter 09. Programming in Assembly

ET2640 Microprocessors

94 CPU (CM8051) Incompatible Instruction ERRATA AND DATASHEET CLARIFICATION V1.0. Leader of Microcontroller Technology A Fabless Semiconductor Company

ELEG3923 Microprocessor Ch.3 Jump, Loop, and Call

Q.1. A) Attempt any THREE of the following:

Microcontroller and Applications

UNIT MICROCONTROLLER AND ITS PROGRAMMING

Microcontroller Lab Manual

MODEL ANSWER SUMMER 17 EXAMINATION Subject Title: Microcontroller Subject Code:

MODULE-1. Short Answer Questions

EE 354 Sept. 2, 2016 A51 Sample Programs

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) SUMMER 14 EXAMINATION Model Answer

MICROCONTROLLER BASED WATER LEVEL CONTROL SYSTEM

The Microcontroller. Lecture Set 3. Major Microcontroller Families. Example Microcontroller Families Cont. Example Microcontroller Families

Section Microcontroller Instruction Set

LCD AND KEYBOARD INTERFACING

Transcription:

EEE3410 Microcontroller Applications LABORATORY Experiment 2 Assembly Language programming (2) Name Class Date Class No. Marks Arithmetic, Logic and Jump instructions Objectives To learn and practice the following basic types of 8051 instructions: - Arithmetic instructions - Logical instructions - Jump instructions To practice the use of 8051 simulation and debugging software in program design Equipment/Components Required Personal computer with Windows XP operating system installed MedWin 8051 simulation software Ver Author(s) Date Remark 1.0 KK SIN 9/2006 Laboratory Experiment 2 1

A. Background Teaching lecturer should go through the topics on Data Movement instructions and Arithmetic and Logic operation instructions with students before carrying out the following laboratory exercise. B. Programming exercise B.1 Arithmetic instructions B.1.1 Use the 8051 simulation software, create and carry out simulated execution of the assembly program in table B.1.1. Table B.1.1 1. ORG 0H 2. MOV DPTR, #040H ; load pointer 3. MOV R2, #3 ; load counter 4. MOV R1, #0H ; set R1 equal to sum 5. AGAIN: CLR A ; A = 0 6. MOVC A, @A+DPTR ; load data to A 7. ADDC A, R1 ; add data to sum 8. MOV R1, A ; store result to sum 9. INC DPTR ; increment pointer 10. DJNZ R2, AGAIN ; repeat until R2 is zero 11. MOV B, #03H ; load B 12. DIV AB ; divide A by B 13. ADD A, R1 ; add A to sum 14. LOOP: SJMP LOOP ; endless loop 15. ORG 40H ; start address of Data 16. DB ABC ; content of data 17. END (1)Execute the program steps by steps until end. Note the change of values in the registers by opening suitable monitoring windows, e.g. the Register window, SFR window, etc. (2) Write down the contents of the following at the end of execution Register Content Register Content A 08H R1 C6H B 00H R2 00H DPTR 0043H CY flag 1 B.1.2 Use the 8051 simulation software, create and carry out simulated execution of the assembly program of BCD calculation in table B.1.2. 2 Experiment 2 Laboratory

Table B.1.2 EEE3410 Microcontroller Applications 1. ORG 0H 2. CLR C ; clear Carry Flag 3. CLR PSW.6 ; clear Auxiliary Carry Flag 4. MOV 40h, #71H ; Initialization of data 5. MOV 41h, #11H ; 6. MOV 42h, #65H ; 7. MOV 43h, #59H ; 8. MOV R0, #40H ; load pointer 9. MOV R1, #3 10. MOV R2, #4 ; load counter 11 CLR A ; A = 0 12. MOV R7, A ;clear R7 13. AGAIN: ADD A, @R0 ; add data pointed by pointer 14. MOV @R1, A 15. DA A ; adjust for BCD 16. JNC NEXT ; if CY=0 don t accumulate carry 17. INC R7 ; keep track of carries 18. NEXT: INC R0 ; increment pointer 19. INC R1 20. DJNZ R2, AGAIN ; repeat until R2 is zero 21. LOOP: SJMP LOOP ; endless loop 22. END a) Execute the program steps by steps until end. Note the change of values in the registers. b) Write down the contents of the following at the end of execution Register Content Register Content A 06H R4 82H R0 44H R5 E7H R2 00H R6 A0H R3 71H R7 02H c) What are the registers storing the BCD result of calculation and what is the result? R7 & A, BCD result after addition of the 4 BCD number = 206 d) Write down the values of the CY, OV & AC flags after the program line 13 is being executed at each time. Program line 13 being executed at CY flag OV flag AC flag 1 st time 0 0 0 2 nd time 0 1 0 3 rd time 0 0 0 4 th time 0 1 1 Laboratory Experiment 2 3

B.2 Logic instructions B.2.1 To perform the logic AND operation on two hexadecimal numbers 18h and 5Bh and keep the result in the Accumulator A. (1) Use the 8051 simulation software, create and carry out simulated execution of the assembly program in table B.2.1 (2) To record the result in Accumulator A after the logic AND operation: A = 18H or 0001 1000 B Table B.2.1 1. ORG 0030H 2. MOV A, #18H ;load A with the value 18h 3. ANL A, #5BH ;AND A with the value 5Bh 4. LOOP: SJMP LOOP ;endless loop 5. END ; B.2.2 To perform the logic OR operation on two hexadecimal numbers 18h and 5Bh and keep the result in the Accumulator A. (1) Use the 8051 simulation software, create and carry out simulated execution of the assembly program in table B.2.2 (2) To record the result in Accumulator A after the logic OR operation: A = 5BH or 0101 1011 B Table B.2.2 1. ORG 0030H 2. MOV A, #18H ;load A with the value 18h 3. ORL A, #5BH ;AND A with the value 5Bh 4. LOOP: SJMP LOOP ;endless loop 5. END ; B.2.3 Perform the logic Exclusive OR (XOR) operation on two hexadecimal numbers 18h and 5Bh, and keep the result in the Accumulator A. (1) Use the 8051 simulation software, create and carry out simulated execution of the assembly program in table B.2.3 (2) To record the result in Accumulator A after the logic XOR operation: A = 43H or 0100 0011 B 4 Experiment 2 Laboratory

EEE3410 Microcontroller Applications Table B.2.3 1. ORG 0030h 2. MOV A, #18h ;load A with the value 18h 3. XRL A, #5Bh ;AND A with the value 5Bh 4. LOOP: SJMP LOOP ;endless loop 5. END ; Note: The operations ANL (logic AND), ORL (logic OR) and XRL (logic Exclusive OR) may take the addressing modes of either Immediate, Direct, Indirect or Register Addressing, the choice of which addressing mode is chosen depends on individual applications. B.2.4 To perform the compare and jump operation (instruction: CJNE & DJNZ) (1) The program in table B.2.4 is to monitor Port 1 (P1) continuously for the value 63H. It should get out of the monitoring only if P1=63H. (2) Use the 8051 simulation software, create and carry out simulated execution of the assembly program in table B.2.4 Table B.2.4 1. ORG 0030H 2. MOV P1, #0FFH ; make P1 as an input port 3. HERE: MOV A, P1 ; get P1 4. CJNE A, #63H, HERE ; keep monitoring unless P1=63H 5. MOV R2, #13H 6. BACK: MOV P2, A 7. CPL A 8. DJNZ R2, BACK 9. LOOP: SJMP LOOP ; endless loop 10. END ; (3) During the simulated execution, use command Peripherals Ports to display Port Windows. By locating the mouse on any port bit, you can toggle the bit status by clicking the left hand button (Bit with white = LOW, bit with colour = HIGH). Use mouse to set the value of Port 1 to 63H. Observe the result. Value of Port 2 will toggle between 0110 0011 and 1001 1100 (4) How many times are the lines from 6 to 8 being executed? 19 times (5) What is the value of A at the end of execution? 9CH Laboratory Experiment 2 5

C. Exercise and Discussion 1. What is the stack pointer (SP) inside the CPU? What is the size of the SP register? SP is a 8-bit register used to hold an internal RAM address that is called the top of the stack. It is the last byte of data that was stored by a stack operation. 2. What is the instruction CJNE and DJNZ stand for? CJNE - Compare the source and destination operands first and then jump to the relative address if they are not equal DJNZ - Decrease operand by 1 first and then jump to the relative address if the result becomes zero 3. Find the content of register A after the following code in each case. a) MOV A, #37h ANL A, #0CAh Accumulator A : 02H b) MOV A, #37h ORL A, #0CAh Accumulator A : FFH c) MOV A, #37h XRL A, #0CAh Accumulator A : FDH 4. To mask certain bits of the accumulator we must ANL it with 0. 5. To set certain bits of the accumulator to 1 we must ORL it with 1. 6. XRL an operand with itself results in 0. 7. What value must R4 have in order for the following instruction not to jump? CJNE R4, #53, OVER R4 = 53 8. Find contents of register A after execution of the following code. CLR A ORL A, #99h CPL A Accumulator A : 66H 9. What is the value of register A after each of the following instruction? MOV A, #25h 25H RR A 92H RR A 49H RR A A4H RR A 52H Accumulator A : 10. What is the value of register A after each of the following instruction? MOV A, #A2h A2H RL A 45H RL A 8AH RL A 15H RL 2AH Accumulator A : 6 Experiment 2 Laboratory

11. What is the value of register A after each of the following instruction? CLR A 0H SETB C 0H RRC A 80H SETB C 80H RRC C0H Accumulator A : 12. What is the value of register A after each of the following instruction? MOV A, #85h 85H SWAP A 58H ANL A, #0F0h 50H Accumulator A : EEE3410 Microcontroller Applications 13. Assume the P1 is an input port connected to a temperature sensor. Write a 8051 program to read the temperature ns test it for the value 80. According to the test results, place the temperature value in to the registers indicated by the following. If T = 80 then A = 80 If T < 80 then R1 = T If T > 80 then R2 = T ORG 00H MOV P1,#0FFH ;set P1 as input port CLR A ;clear A MOV R1,A ;clear R1 MOV R2,A ;clear R2 MOV A,P1 ;input T from P1 to A CJNE A,#80,NOT_EQ ;jump if T 80 SJMP STOP ;end if T=80 NOT_EQ: JC LOW ;jump if T<80 HIGH: MOV R2,A ;save T to R2 CLR A ;clear A SJMP STOP LOW: MOV R1,A ;save T to R1 STOP: CLR A ;clear A NOP END - End - Laboratory Experiment 2 7