PowerPC -- Assembling the working source code |
The 68K code necessary to test the code for Task 1 is
# A Routine for SUM <- [FIRST] + [SECOND] #************************************************** SUM: EQU 0x7200 # Specify location to store the result section const .EXPORT FIRST FIRST: DC.W 0x123 # FIRST = 0x123 SECOND: DC.W 0x456 # SECOND = 0x456 section code .EXPORT mycode mycode: MOVE.W FIRST, D0 # D0 <- [FIRST] ADD.W SECOND, D0 # D0 <- [D0] + [SECOND] MOVE.W D0, SUM # SUM <- [D0]
During the WIDFI process we obtained information about the DIAB DATA PowerPC assembly language directives that are still valid with the demo kit. The resulting source code file based on translating a LOAD/STORE version of the 68K code for Task 1 into the proper PowerPC instructions and DIAB DATA assembler directives is the source file t1v2.s which we can pass through the DIAB das assembler.
# A PowerPC routine for SUM <- [FIRST] + [SECOND]
**************************************************
SUM: .equ 0x7200 # Specify location to store the result .text # section const .global FIRST FIRST: .short 0x123 # FIRST = 0x123 SECOND: .short 0x456 # SECOND = 0x456 .text # section code .global mycode mycode: # MOVEA.L #FIRST, A0 ADDI R3, 0, FIRST@l # (On PowerPC move bottom 16 bits, ADDIS R3, R3, FIRST@h # then top 16 bits of address FIRST) LHZ R4, 0(R3) # MOVE.W (A0), D0 # MOVEA.L #SECOND, A0 ADDI R3, 0, SECOND@l # (On PowerPC move bottom 16 bits, ADDIS R3, R3, SECOND@h # then top 16 bit of address SECOND) LHZ R5, 0(R3) # MOVE.W (A0), D1 (Note the change) ADD R4, R4, R5 # ADD.W D1, D0 # MOVEA.L #SUM, A0 ADDI R3, 0, (SUM & 0xFFFF) # (On PowerPC move bottom 16 bits, ADDIS R3, R3, (SUM >> 16) # then top 16 bits of address SUM) STH R4, 0(R3) # MOVE.W D0, (A0)
The PowerPC source file t1v2.s will suffer from all the same problems during simulation as we found with our initial 68K source file.
Unfortunately, because of the way that the PowerPC demo kit has been released, the PowerPC solutions to all the above problems are not "as clean" as the 68K solutions. You can follow the links to get more details of the problems that I experienced.
When we solve all these problems, the final PowerPC source file "ppcfinal.s" has the following appearance
# A PowerPC routine for SUM <- [FIRST] + [SUM] #************************************************** # The .include directive does not work. The file "startup.i" # must be hard coded into the file. Cut and Paste to # use in future source files. This code was derived from # information in file "crt0.s" # .include "startup.i" .file "ppcfinal.c" # Read the web page to find out why .text # section code .global START # .EXPORT START # .extern __SP_INIT # .IMPORT STKTOP START: ADDIS R11, R0, __SP_INIT@ha # Setting the stack pointer ADDI R1, R11, __SP_INIT@l ADDI R0, R0, 0 STWU R0, -24-32(R1) # MOVEA.L #STKTOP, SP BL mycode # JSR mycode # Set up illegal instruction to force program to stop CAUSECRASH: .equ 0x0 .long CAUSECRASH # TRAP #15 #***** end of .include "startup.i" **************** #************************************************** SUM: .equ 0x7200 # Specify location to store the result .text # section const .global FIRST FIRST: .short 0x123 # FIRST = 0x123 SECOND: .short 0x456 # SECOND = 0x456 .text # section code .global mycode mycode: # MOVEA.L #FIRST, A0 ADDI R3, 0, FIRST@l # (On PowerPC move bottom 16 bits, ADDIS R3, R3, FIRST@h # then top 16 bits of address FIRST) LHZ R4, 0(R3) # MOVE.W (A0), D0 # MOVEA.L #SECOND, A0 ADDI R3, 0, SECOND@l # (On PowerPC move bottom 16 bits, ADDIS R3, R3, SECOND@h # then top 16 bit of address SECOND) LHZ R5, 0(R3) # MOVE.W (A0), D1 (Note the change) ADD R4, R4, R5 # ADD.W D1, D0 # MOVEA.L #SUM, A0 ADDI R3, 0, (SUM & 0xFFFF) # (On PowerPC move bottom 16 bits, ADDIS R3, R3, (SUM >> 16) # then top 16 bits of address SUM) STH R4, 0(R3) # MOVE.W D0, (A0)
The final source code for Laboratory 1 can be found in the file "ppcfinal.s". It can be assembled using the syntax
das -l ppcfinal.s
to give an object file "ppcfinal.o" and a listing file "ppcfinal.l".
This command can be issued from the command line of a DOS window. For those who prefer to use the SDS assembler GUI interface, follow this link to see how to set up the interface for assembling files.
You will need a copy of the PowerPC memory specification file ppc.lnk before moving on to WIDFI stage 6 where we activate the PowerPC linker and simulator to run the code.
The DIAB DATA assembler is not very friendly. The -l option automatically generates a listing file, ppcfinal.l. From a DOS window the assembler sends the error messages to the screen, too fast to read if you have a large number of them. This is a problem since the error messages don't also go into the listing file, despite what the DIAB manual says. Perhaps another "crippling" for the demo kit. It should be possible to capture the error messages from the screen and write a small "C" filter to insert them back into the listing file. Watch out for this filter on my WEB site.
Those who used using the 68K SDS assembler GUI interface and liked the feature of double clicking on the error messages in the Error Window will be pleased to learn that this feature does not work in the PowerPC demo version. You'll have to take the error messages down with perncil and paper and match them with the offending source lines by hand.
![]() |
Last modified: July 22, 1996 02:01 PM by M. Smith.
Copyright -- M. R. Smith