Problem #1- Write a subroutine (not a program) in 68000 assembly language that will count the number
Question:
Problem #1- Write a subroutine (not a program) in 68000 assembly language that will count the number of 1 bits in a sequential series of bytes between two memory locations. The starting and ending memory locations are passed into the subroutines as 32-bit addresses in registers A0 and A1, and the number of bits are returned in register D7 as a 32-bit long word.
The bytes should be counted from the starting address up to, but not including, the ending address. It is not necessary to check that the addresses are correctly specified. You may assume that the address in register A0 is at least two bytes less than the address in register A1.
I've included a very short "scaffold" program that you will need to complete to test your subroutine. It can call the subroutine and receive the return value. In the scaffold program you could use the "Declare Constant Block" directive to load a block of memory that you will be using for your subroutine to work with, or you can just load some numbers in with the DC.B command. The scaffold program is how we will test your subroutine. The scaffold program and your subroutine should be created as a single program with both elements.
Deliverables: You will submit the following:
1- A flow chart of your subroutine.
2- A paper copy of the list file of your subroutine and scaffold program. The list file should be in landscape format with no word wrap. Points will be deducted from improperly formatted list files.
3- Your subroutine and scaffold program on a flash drive. The flash drive will be returned to you. You should name your program HW4.X68 and it should be at the top level on the drive. Don't bury it in a folder.
Discussion: This is a great opportunity to hone your skills and learn how subroutines work. Also, it is a very easy program to test because you can easily parameterize the starting and ending blocks of the program. The DCB directive enables you to fill a block with a known value so you can check if your program counts it properly. Also, it is so easy to try something out using Easy68K. You can try something in less than a minute. To test your program, a good trick is to make the block of memory very small, say 10 bytes or less. Put in some easy data to calculate by hand.
Hints:
a- Review the memory test program that we studied in class to see how a subroutine is structured. Make sure you save any registers that you will use in the program and restore them on exit. Make sure that your header block is fully descriptive of how the subroutine works.
b- In order to set up a block with a known value consider the skeleton program shown below:
c- The next obvious issue is "How the HECK do I count 1-bits?" Good question. There are several ways you could do it. You could consult "rent-a-coder.com" and buy the program, but that won't help on the exam. You could search the internet for a program that does what you want and maybe you'll be lucky. Or, you could design your own program. So, assuming you want to design your own, you might think about these interesting instructions. BTST is a good one to use, and so is ROL or ROR. Both give you a mechanism to test the value of a single bit and see what it is. So you can either ROLL the bits through the carry position and see if it is a one or a zero ( BCS or BCC ) or use the BTST successively 8 times and test the Z bit ( BEQ and BNE ).
d- Be sure to properly set up the registers that you will need to use. Just because the simulator automatically sets the virtual registers to zero doesn't mean that the real 68000 will be just as convenient.
e- Here's some help to get you started.
*-----------------------------------------------------------
* Program :Skeleton program to test a bit counter subroutine
* Written by : XXXX
* Date : XXX
* Description: This program will exercise the subroutine that actually counts the number of 1 bits over a region of
* memory.
*-----------------------------------------------------------
******************Equates***********************************
MEMSTART EQU $00002000 *Starting address of example block to count bits
MEMEND EQU $00003000 *Ending address of example block to count bits
ORG $1000 * Program runs here
START: * first instruction of program
* Here is where your code initializes the registers and your pointers
* Make sure stack pointer is set !
JSR your_routine * Here's the call to your subroutine
MOVE.B #9,D0
TRAP #15 * halt simulator
***********************************
* SUBROUTINE: Name of your subroutine.
* You subroutine goes here. This is your header block
*
***********************************
your_routine {First instruction goes here} *See how the label is used
* Variables and Strings
* Observe how I use the capabilities of the assembler to figure out the size of the memory block to fill.
* All I needed to do was use my variables MEMSTART and MEMEND and the assembler figures out the block
* size for me.
* So, for testing, all I need to do is define a manageable block size
COUNT_HERE ORG MEMSTART * The ORG statement defines the start of the block
DCB.B MEMEND-MEMSTART,$01 * Let the assembler do the work. I'm counting one 1 bit per
* byte.
* Using this value makes counting easy!
END START * last line of source
Digital Systems Design Using Verilog
ISBN: 978-1285051079
1st edition
Authors: Charles Roth, Lizy K. John, Byeong Kil Lee