ECE 3120 Computer Systems HCS12 Assembly Programming -Review

Similar documents
HC12 Assembly Language Programming

Lecture 3 Addressing Modes, Instruction Samples, Machine Code, Instruction Execution Cycle

M6800. Assembly Language Programming

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Programming the Motorola MC68HC11 Microcontroller

Programmer s Model = model of µc useful to view hardware during execution of software instructions

Introduction to Microcontrollers

How To Understand All Instructions In The Power12 Program

The stack and the stack pointer

U:\montages\dominique\servo\moteur_AV_AR\program\moteur_AV_AR.asm jeudi 28 avril :32

Microprocessor/Microcontroller. Introduction

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

8085 INSTRUCTION SET

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

6800 Basics. By Ruben Gonzalez

MACHINE ARCHITECTURE & LANGUAGE

LABORATORY MANUAL EE0310 MICROPROCESSOR & MICROCONTROLLER LAB

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k Design Consultant

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Z80 Instruction Set. Z80 Assembly Language

How To Write A Microsoft Microsoft 8D (Droid) (Program) (Powerbook) (I386) (Microsoft) (Donga) (Opera) And (Dungeo) (Dugeo

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Modbus RTU Communications RX/WX and MRX/MWX

PART B QUESTIONS AND ANSWERS UNIT I

Lecture 8: Binary Multiplication & Division

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

The string of digits in the binary number system represents the quantity

Reduced Instruction Set Computer (RISC)

Instruction Set Architecture

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

ELEG3924 Microprocessor Ch.7 Programming In C

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

THUMB Instruction Set

CPU Organization and Assembly Language

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Binary Numbers. Binary Octal Hexadecimal

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

2011, The McGraw-Hill Companies, Inc. Chapter 3

CS201: Architecture and Assembly Language

MICROPROCESSOR AND MICROCOMPUTER BASICS

Number and codes in digital systems

CPEN Digital Logic Design Binary Systems

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Decimals Adding and Subtracting

1 Classical Universal Computer 3

Computer organization

8-bit RISC Microcontroller. Application Note. AVR236: CRC Check of Program Memory

Application Note. General Description. AN991/D Rev. 1, 1/2002. Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers

Classless Subnetting Explained

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Chapter 7D The Java Virtual Machine

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

5 Combinatorial Components. 5.0 Full adder. Full subtractor

CYCLIC REDUNDANCY CHECKS IN USB. Introduction. Two-minute mathematical background

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

PROBLEMS (Cap. 4 - Istruzioni macchina)

8085 MICROPROCESSOR PROGRAMS

Real-time system programs

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

APPENDIX B. Routers route based on the network number. The router that delivers the data packet to the correct destination host uses the host ID.

NUMBER SYSTEMS. 1.1 Introduction

Introduction to MIPS Assembly Programming

3. Convert a number from one number system to another

Lecture 11: Number Systems

Instruction Set Architecture (ISA)

Binary Representation

EE282 Computer Architecture and Organization Midterm Exam February 13, (Total Time = 120 minutes, Total Points = 100)

Microprocessor & Assembly Language

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

CHAPTER 7: The CPU and Memory

Typy danych. Data types: Literals:

Chapter 2. Binary Values and Number Systems

Complete 8086 instruction set

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

What Is Singapore Math?

68HC11 Programmer s Reference Manual

Application Note AN_106. Interfacing to a USB Printer using Vinculum VNC1L Host Controller

Analog to Digital Converters. By: Dapeng Zhu Todd Sifleet Travis Nunnally Yachun Huang

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Parallel I/O Interface to the Neuron Chip

Faculty of Engineering Student Number:

Computer Organization and Architecture

ASCII and BCD Arithmetic. Chapter 11 S. Dandamudi

Notes on Assembly Language

Computer Science 281 Binary and Hexadecimal Review

MACHINE INSTRUCTIONS AND PROGRAMS

Systems I: Computer Organization and Architecture

Useful Number Systems

X86-64 Architecture Guide

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

A Utility for Programming Single FLASH Array HCS12 MCUs, with Minimum RAM Overhead

Transcription:

ECE 3120 Computer Systems HCS12 Assembly Programming -Review Manjeera Jeedigunta http://blogs.cae.tntech.edu/msjeedigun21 Email: msjeedigun21@tntech.edu Tel: 931-372-6181, Prescott Hall 120

Program Structure LABEL: OPCODE OPERAND ;Comments Assembler Directives Initializations Reserving Memory Declaring array elements Main Logic of the program

Arithmetic Programming Addition Subtraction Multiprecision Addition (Carry Flag) Multiprecision Subtraction (Borrow Flag) BCD Multiplication Division

Example1: Addition of 16 bit numbers Write a program to add two 16 bit numbers, one of which is $1234 and the other is stored at memory location $1000~1001. Store the result in $2000 org $1500 ldd #$1234 ;place 16 bit number in D ;D=$1234 addd $1000 ;D + m[$1000]:m[$1001]d std $2000 ;Sum $2000

Example2: Subtraction & Addition Write a program to add two 16 bit numbers, one of which is at $1000~$1001 and the other is stored at memory location $1002~1003 and subtract a 16 bit number that is stored in $1100~1101from the sum. Store the result in $2000 $1001 $1000 $1003 $1002 $1101 $1100 D $2001 $2000 D+m[$1002]:m[$1003]D D-m[$1100]:m[$1101]D org $1500 ldd $1000 ;Dm[$1000]:m[1001] addd $1002 ;DD+m[$1002]:m[$1003] subd $1100 ;DD-m[$1100]:m[$1101] std $2000 ;m[$2000]d

Example3: Multiprecision Addition Write a program to add two 4 byte numbers that are stored at $2000~$2003 & $2100~$2103 and store the result at $2200~$2203 $2002 C A + $2103 C A + $2102 $2002 A $2101 + B $2100 $2001 $2000 $2003 $2002 $2001 $2000 $2103 $2102 $2101 $2100 $2203 $2202 $2201 $2200 SumA SumA SumD $2203 $2202 $2202 $2202

Example 3: Multiprecision Addition Write a program to add two 4 byte numbers that are stored at $2000~$2003 & $2100~$2103 and store the result at $2200~$2203 $2003 $2002 $2001 $2000 $2103 $2102 $2101 $2100 $2203 $2202 $2201 $2200 org $1000 ldd $2000 ;Dm[$2000]:m[$2001] addd $2100 ;DD+m[$2100]:m[$2101] std $2200 ;m[$2200]d ldaa $2002 ;Am[$2002] adca $2102 ;AA+m[$2102] staa $2202 ;m[$2202]a ldaa $2003 ;m[$2003] adca $2103 ;AA+m[$2103] staa $2203 ;m[$2203]a

Example 4: Multiprecision Subtraction Write a program to subtract two 4 byte numbers that are stored at $2000~$2003 & $2100~$2103 and store the result at $2200~$2203 $2003 $2002 $2001 $2000 $2103 $2102 $2101 $2100 $2203 $2202 $2201 $2200 org $1000 ldd $2000 ;Dm[$2000]:m[$2001] subd $2100 ;DD-m[$2100]:m[$2101] std $2200 ;m[$2200]d ldaa $2002 ;Am[$2002] sbca $2102 ;AA-m[$2102] staa $2202 ;m[$2202]a ldaa $2003 ;m[$2003] sbca $2103 ;AA-m[$2103] staa $2203 ;m[$2203]a

Example 5: Multiplication Write a program to multiply two signed 16 bit numbers that are stored at $2000~$2001 & $2100~$2101and store the result at $2200~$2201 $2000~$2001 $2100~$2101 D * Y emuls Y D $2200~$2201 org $1000 ldd $2000 ;Dm[$2000]:m[$2001] ldy $2100 ;Y [$2100]:m[$2101] emuls std $2201 ;m[$2201]d sty $2200 ;m[$2200]y

Example 6: Division Write an instruction sequence to divide the signed 16-bit number stored at $1005- $1006 by the signed 16-bit number stored at $1020-$1021 and store the quotient and remainder at $1030-$1031 and $1032-$1033, respectively. D LSB of Dividend MSB of Dividend $1006 $1005 idivs D LSB of Rem MSB of Rem $1033 $1032 X LSB of Divisor MSB of Divisor $1021 $1020 X LSB of Quotient MSB of Quotient $1031 $1030 ldd $1005 ;load the dividend into D ldx $1020 ;load the divisor into X idivs ; perform signed division stx $1030 ;storing the quotient std $902 ;storing the remainder

Example 2.11 Write an instruction sequence to divide the signed 16-bit number stored at $1005-$1006 by the signed 16-bit number stored at $1020-$1021 and store the quotient and remainder at $1030-$1031 and $1032-$1033, respectively. D LSB of Dividend MSB of Dividend $1006 $1005 idivs D LSB of Rem MSB of Rem $1033 $1032 X LSB of Divisor MSB of Divisor $1021 $1020 X LSB of Quotient MSB of Quotient $1031 $1030 ldd $1005 ;load the dividend into D ldx $1020 ;load the divisor into X idivs ; perform signed division stx $1030 ;storing the quotient std $902 ;storing the remainder

Example 7 : BCD Write a program to add the 4 digit BCD numbers that are stored at $2000~$2001 & $2100~$2101and store the result at $2200~$2201 Similar to normal addition, except we have to take care of the decimal adjustment part by using the daa instruction. Works with only reg A so have to work with one byte at a time starting from the LSB org $1000 lda $2001 ;Am[$2001 adaa $2101 ;AA+m [$2101] daa ;decimal adjust lower byte staa $2201 ;m[$2201]a lda $2000 ;Am[$2000] adaa $2100 ;AA+m [$2100] daa ;decimal adjust Higher byte staa $2200 ;m[$2200]a C + $2000 A $2100 + DAA SumA $2001 A + $2100 + DAA SumA $2201 $2200

Example 8 :Loops Write a program to compute the sum of 10, 16-bit unsigned numbers stored at the memory address $1000~$1020 and store the result in $1100~$1103 N equ 10 ;array count org $1000 ;starting address of the elements array dw 320,333,321,420,500,550,620,700,400,300 sum rmb 4 ;array sum i rmb 1 ;array index org $1500 ;starting addr of program ldaa #0 staa sum ;initiallize sum to 0 staa sum ; staa sum ; staa sum ; staa i ; intialize loop counter zero Start i 0 sum 0 i = N? no sum sum + array[i] i i + 1 yes Stop

Example 8 : Loops Contd.. loop ldab i ;Bi done cmpb #N ;is i=n? beq done ;if i=n then branch to label done ldx #array ;use index register X as pointer to the array, X=$1000 abx ;XX+B = X+I, to compute the ;addr of current element ldd 0,x ;place array[i] in D addd sum+2 ;DD+sum std ldaa #0 sum+2 adca sum+1 ;propagating carry to msb staa sum+1 inc i ;moving to next element inc bra swi I loop S Start i 0 sum 0 i = N? no sum sum + array[i] Carry i i + 1 S+1 yes S+2 Stop S+3 Sum of nos end

Example 9: Bit Condition Branch Instructions Write a program to count the number of elements that are divisible by 4 in an array of N 8-bit numbers Numbers divisible by 4 have the least significant two bits to be 00 N equ 10 org $1000 ;starting address of the 1 st element in the array array db 1,2,3,4,5,6,7,8,9,10 total rmb 1 ;variable counting no.of elements divisible by 4 org $1500 ;starting address of the program clr total ;initializing counter to 0 ldx #array ;loading x with the address of the array, X= $1000 ldab #N ;B is used as the loop counter loop brclr 0,x,$03,yes ------------------------------------------------------------------------------------------------- Operand at the memory location pointed by 0,x 00000100 Operand provided by the mask in the instr 00000011 AND result = 0 Execution will branch to the location specified in the label (yes)

Example 9: Bit Condition Branch Instructions Write a program to count the number of elements that are divisible by 4 in an array of N 8-bit numbers Numbers divisible by 4 have the least significant two bits to be 00 N equ 10 org $1000 ;starting address of the 1 st element in the array array db 1,2,3,4,5,6,7,8,9,10 total rmb 1 ;variable counting no.of elements divisible by 4 org $1500 ;starting address of the program clr total ;initializing counter to 0 ldx #array ;loading x with the address of the array, X= $1000 ldab #N ;B is used as the loop counter loop brclr 0,x,$03,yes bra chkend yes inc total ;add 1 to total as the number is divisible by 4 chkend inx ;move the array pointer dbne b,loop end

Example 10: Bit Condition Branch Instructions Write a program to count the number of elements that whose bit 1,4,7 are 1 s using brset 7 6 5 4 3 2 1 0 1 0 0 1 0 0 1 0 Mask = $49 N equ 10 org $1000 ;starting address of the 1 st element in the array array db 1,2,3,4,5,6,7,8,9,10 total rmb 1 ;variable counting no.of elements having the required pattern org $1500 ;starting address of the program clr total ;initializing counter to 0 ldx #array ;loading x with the address of the array, X= $1000 ldab #N ;B is used as the loop counter loop brclr 0,x,$49,yes ------------------------------------------------------------------------------------------------- Operand at the memory location pointed by 0,x 11010110 Inv 00101001 Operand provided by the mask in the instr 10010010 AND result = 0 Execution will branch to the location specified in the label (yes)

Example 10: Bit Condition Branch Instructions Write a program to count the number of elements that whose bit 1,4,7 are 1 s using brset 7 6 5 4 3 2 1 0 1 0 0 1 0 0 1 0 Mask = $49 N equ 10 org $1000 ;starting address of the 1 st element in the array array db 1,2,3,4,5,6,7,8,9,10 total rmb 1 ;variable counting no.of elements with the pattern org $1500 ;starting address of the program clr total ;initializing counter to 0 ldx #array ;loading x with the address of the array, X= $1000 ldab #N ;B is used as the loop counter loop brset 0,x,$49,yes bra chkend yes inc total ;add 1 to total as the number has the required pattern chkend inx ;move the array pointer dbne b,loop end

Example 11: Shift Write a program to count the number of 1 s contained in the memory locations $2000~$2001 and save the result at memory location $1000 org $2000 word: dc.w $2355 ;number to be worked on one_ct rmb 1 lp_ct rmb 1 org $1500 ;starting addr of program clr one_ct ;initializing to 0 movb #16,lp_ct ;initializing to 16 ldd word ;place 16 bit number in D again lsrd ;shift right by 1 place bcc chkend ;branch if lsb is a 0 inc one_ct ;in case of C=1 chkend dec lp_ct bne again ;chk to see if we tested all ;16 bits end Zero count++ Loop count =16, Zero cnt =0; Dm[$2000]: m[$2001] Shift D right by 1 Yes If C=1 Dec loop cnt If loop cnt = 16 END No

Example 12:Booloean Logic Instructions Write a sequence of instructions to clear the lower 4 pins of the I/O port located at $82 using AND ldaa $82 ;loading the contents of the mem location $82 into A anda #$F0 ;clearing lower 4 bits in A staa $82 ;Am[$82] -------------------------------------------------------------------------------------------------------- m[$82] =10101010 Mask=$F0=11110000 AND =10100000

Example 13: Boolean Logic Instructions Write a sequence of instructions to set the bit 7 of the I/O port located at $82 using OR ldaa $82 ;loading the contents of the mem location $82 into A ora #$80 ;sets bit 7 in A staa $82 ;Am[$82] -------------------------------------------------------------------------------------------------------- m[$82] =00101010 Mask=$80=10000000 OR =10101010

Example 14: Boolean Logic Instructions Write a sequence of instructions to toggle the upper four bits of the I/O port at $82 ldaa $82 ;loading the contents of the mem location $82 into A eora #$F0 ;toggles upper 4 bits in A staa $82 ;Am[$82] -------------------------------------------------------------------------------------------------------- m[$82] =10101010 Mask=$F0=11110000 XOR =01011010

Example 15: Bit Test & Manipulate Write a sequence of instructions to clear the upper four bits at $82 bclr $82,$F0 Write a sequence of instructions to set the upper four bits at $82 bset $82,$F0 Write a sequence of instructions to test the upper four bits at $82 ldaa $82 bita #$F0

Chapter Review Assembly Language Program Structure: Label, operation, operand, comment Directives: end,org,db,ds,fill Flow chart Arithmetic Loops, branch instructions Shift and rotate Boolean logic Bit test and manipulate Program execution time

Now, you should be able to: Allocate memory blocks, define constants, and create a message using assembler directives Write assembly programs to perform simple arithmetic operations Write loops to perform repetitive operations Use loops to creat time delays Use boolean and bit manipulation instructions to perform bit field operations.