TUTORIAL Assembly Language programming (2)

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

Microcontroller Intel [Instruction Set]

Assembly Language programming (2)

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

Programming of 8085 microprocessor and 8051 micro controller Study material


Principle and Interface Techniques of Microcontroller

8051 Microcontrollers

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

8051 Programming: Arithmetic and Logic

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

8051 Overview and Instruction Set

SN8F5000 Family Instruction Set

Microcontroller. Instruction set of 8051

Module Contents of the Module Hours COs

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

8051 Microcontroller

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Dodatak. Skup instrukcija

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

8051 Programming using Assembly

Digital Blocks Semiconductor IP

DR bit RISC Microcontroller. Instructions set details ver 3.10

Dragonchip. Instruction Set Manual

Digital Blocks Semiconductor IP

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

Arithmetic and Logic

Digital Blocks Semiconductor IP

Instruction Set Of 8051

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

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

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

ENE 334 Microprocessors

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

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

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

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

~: Simple Programs in 8051 assembly language :~

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO.

MCS -51 Programmer s Guide and Instruction Set

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

C51 Family. Architectural Overview of the C51 Family. Summary

MICROPROCESSOR LABORATORY MANUAL

Embedded Controller Programming

Assembly Language programming (3)

Chapter 3. Bit Addressable Area. By DeccanRobots

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

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

8051 Microcontroller Assembly Programming

Application Brief D-005

Principle and Interface Techniques of Microcontroller

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

Highlights. FP51 (FPGA based 1T 8051 core)

8051 Core Specification

ELEG3924 Microprocessor

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

Assembly Language Programming Assignment 1

Microcontroller and Applications

CS 320. Computer Architecture Core Architecture

Y51 Microcontroller. Technical Manual

APPLICATION NOTE 601 Accelerating 16/32-Bit Math Operations with the DS80C390/ DS80C400

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

JUMP, LOOP AND CALL INSTRUCTIONS

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

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

Contents. Join the Technical Community Today!

S.J.P.N Trust's. Hirasugar Institute of Technology, Nidasoshi.

EXPERIMENT NO.1. A Microcontroller is a complete computer system built on a single chip.

ELEG3924 Microprocessor

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

AL8051S 8-BIT MICROCONTROLLER Application Notes

Question Bank Microprocessor and Microcontroller

Assembly Language programming (1)

Assembly Language Programming of 8085

Arithmetic and Logic Instructions And Programs

Application Brief D-002

S3C80E5/P80E5/C80E7/P80E7 (Preliminary Spec)

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

Introduction to uc & Embedded Systems

CPEG300 Embedded System Design. Lecture 3 Memory

ELEG3923 Microprocessor Ch.3 Jump, Loop, and Call

UNIT MICROCONTROLLER AND ITS PROGRAMMING

Microcontroller Lab Manual

Chapter Family Microcontrollers Instruction Set

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

Microcontrollers can be considered as self-contained systems with a processor, memory and I/O ports.

Arithmetic Instructions

Legacy documentation refer to the Altium Wiki for current information. TSK51x MCU

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

Lecture Instruction Set

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Report Title: Digital Voltmeter using 89C51

ET2640 Microprocessors

SUMMER 13 EXAMINATION

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Legacy documentation refer to the Altium Wiki for current information. TSK52x MCU

Assembly Language Programming of 8085

ELEG3923 Microprocessor Ch.4 I/O Ports

Transcription:

8051 Assembly Language programming (2) TUTORIAL 4 EEE3410 Microcontroller Applications 1. Write the instructions to move value 34h into register A and value 3Fh into register B, then add them together. A, #34h B, #37h ADD A,B 2. Write the instructions to add the values 16h and CDh. Place the result in register R2. R2, #0CDh A, #16h ADD A,R2 R2,A 3. The instruction ADD A, source places the sum in _register A. A, source + A A 4. Why is the following ADD instruction illegal? ADD R1, R2 Rewrite the instruction above in correct form. The destination address must be A. (ADD Rn, Rn is invalid) A,R2 ADD A,R1 R1,A 5. The instruction ADDC A, source places the sum in. Register A, ADD with carry, Source + A + Carry A 6. Find the value of the A and CY flags in each of the following. (a) A, #4Fh (b) A, #9Ch ADD A, #0B1h ADD A, #63h (a) A = 00, CY=1 Since 4Fh + B1h = 0100 1111 + 1011 0001 = 1 0000 0000 (b) A = FF, CY=0 Since 9Ch + 63h = 1001 1100 + 0110 0011 = 1111 1111 7. Show how the CPU would subtract 05h from 43h. 43h 05h Add 2 s complement of 05H to 43h CLR C A, #43h SUBB A,#05h ; 2 complement of representation for 05 (10) = 1111 1011 (2) ; 0100 0011 ; + 1111 1011 ;----------------- ; 1 0011 1110 ; CY=0 (step 3), A=3Eh Tutorial 4 Week 6 1

8. If CY = 1, A = 95h, and B = 4Fh prior to the execution of SUBB A, B, what will be the contents of A after the subtraction? SETB C A,#95h B,#4Fh SUBB A,B A = 95h 4Fh 1 (Carry) = 46h -1 = 45h 9. In multiplication of two bytes in the 8051, we must place one byte in register and the other byte in register. Register A and Register B, MUL AB 10. In unsigned byte by byte multiplication, the product will be placed in register(s). MUL AB : A x B AB (16 bits) 11. Is this a valid 8051 instruction? Explain your answer. MUL A, R1. The source addresses of Multiplication Operation must be in A and B 12. In byte/byte division, the numerator must be placed in register and the denominator in register. Register A and Register B, DIV AB 13. In unsigned byte/byte division, the quotient will be placed in register and the remainder in register. DIV AB : A / B AB, Quotient A, Remainder B 14. Is this valid 8051 instruction? Explain your answer. DIV A, R1. The source addresses of Division Operation must be in A and B 15. In an 8-bit operand, bit is used for the sign bit. Bit 7 16. Convert 16h to its 2 s complement representation. +16h=0001 0110, 1 s complement=1110 1001, 2 s complement = 110 1001+1=1110 1010 17. The range of byte-sized signed operands is to +. -128 to +127 (2 s complement refer to teaching slide chapter 3) 18. Explain the difference between a carry and an overflow. CY : Carry Flag; used in arithmetic, JUMP, ROTATE, and BOOLEAN instruction Unsigned arithmetic OV : Overflow flag; used in arithmetic instructions (signed arithmetic) 19. Find the content of register A after the following code in each case. (a) A, #37h (b) A, #37h (c) A, #37h ANL A, #0CAh ORL A, #0CAh XRL A, #0CAh (a) A, #37h ANL A, #0CAh A = 02h (b) A, #37h ORL A, #0CAh A = FFh (c) A, #37h XRL A, #0CAh A = FDh 20. To mask certain bits of the accumulator we must ANL it with. ZERO 21. To set certain bits of the accumulator to 1 we must ORL it with. 2 Week 6 Tutorial 4

EEE3410 Microcontroller Applications ONE 22. Perform XRL operation on an operand with itself results in. ZERO 23. Find contents of register A after execution of the following code. CLR A ORL A, #99h CPL A CLR A 0h ORL A, #99h 99h CPL A 66h 24. What is the value of register A after each execution of the following instructions? (a) A, #25h (b) A, #A2h (c) CLR A RR A RL A SETB C RR A RL A RRC A RR A RL A SETB C RR A RL A RRC A A, #25h 25h A, #A2h A2h CLR A 0h RR A 92h RL A 45h SETB C 0h RR A 49h RL A 8Ah RRC A 80h RR A A4h RL A 15h SETB C 80h RR A 52h RL A 2Ah RRC A C0h 25. Why does RLC R1 give an error in the 8051? The source address of RLC operation must be in A 26. What is in register A after the execution of the following code? A, #85h SWAP A ANL A, #0F0h A, #85h SWAP A /* 58h ANL A, #0F0h /* 50h 27. The instruction A, 40h uses addressing mode. Why? Direct Addressing Mode 28. Which registers are allowed to be used for register indirect addressing mode if the data is in on-chip RAM? R0 & R1 29. Identify the addressing mode for each of the following: (a) B, #34h (b) A, 50h (c) R2, 07 (d) R3, #0 (e) R7, 0 (f) R6, #7Fh (g) R0, A (h) B, A (i) A, @R0 (a) Immediate (b) Direct (c) Direct (d) Immediate (e) Direct (f) Immediate (g) Register (h) Register (i) Indirect 30. Compare the following 8051 instructions in terms of the number of bytes per instruction, machine cycle per instruction and effective jump address range. (a) SJMP (b) AJMP (c) LJMP Tutorial 4 Week 6 3

Bytes Machine Cycles SJMP 2 2 Relative: Program counter + offset = Effective address = address of next instruction AJMP 2 2 Absolute 2K LJMP 3 2 Long 64K 31. Assume that 5 binary data items are stored in RAM locations starting at 40h, as shown below. Write a program to find the sum of all the numbers. The result then is stored in RAM location 50h. RAM location 40h = (71) RAM location 41h = (11) RAM location 42h = (65) RAM location 43h = (59) RAM location 44h = (37) ANS: ORG 0H SUM_HB EQU 51H ;HIGN BYTE SUM_LB EQU 50H ; LOW BYTE 40H,#71 41H,#11 42H,#65 43H,#59 44H,#37 SUM_HB,#0 SUM_LB,#0 A,SUM_LB R0,#40H CONTINUE: ADD A,@R0 JNC NO_CY_OCCUR INC SUM_HB NO_CY_OCCUR: INC R0 CJNE R0,#45H,CONTINUE SUM_LB,A ; SAVE nop END 4 Week 6 Tutorial 4

EEE3410 Microcontroller Applications 32. If the 5 binary data items in Q31 are in BCD format, write a program to find the sum of all the numbers. The result must be in BCD format and is stored in RAM location 50h. ORG 0H SUM_HB EQU 51H SUM_LB EQU 50H CONTINUE: ACALL ; return in ACC 40H,#71 41H,#11 42H,#65 43H,#59 44H,#37 SUM_HB,#0 SUM_LB,#0 A,SUM_LB R0,#40H A,@R0 TO_BCD ADD A,SUM_LB DA A JNC NO_CY_OCCUR INC SUM_HB NO_CY_OCCUR: SUM_LB,A ;SAVE INC R0 CJNE R0,#45H,CONTINUE NOP SJMP $ TO_BCD: ; input :ACC, output ACC ;eg. input ACC=71 decimal ;output Acc=71H B,#10 ;eg. ACC=71 DIV AB ;eg. A=7 B=1 END R7,B ;eg. R7=1 B,#16 ; MUL AB ; A=70H, B=0H ADD A,R7 ; A=71H RET -- END -- Tutorial 4 Week 6 5