Assembly language CSUBs written on the Pascal Workstation can be ported to theHP-UX operating system for use as BASIC/UX CSUBs. This is accomplished by translating the Pascal Workstation assembly language source file using the HP-UX command called atrans and then making any necessary changes to the program. This chapter provides you with a process for doing this, however, it requires a good background in assembly language programming with the 68000 microprocessor.
As previously mentioned, you will need a good understanding of assembly language programming on a 68000 microprocessor in order to translate a Pascal Workstation assembly language program into one for use on HP-UX. Note that the MC68010 is not supported on BASIC/UX. The following are prerequisites for porting your Pascal Workstation assembly language program:
This section explains how to translate your Pascal Workstation assembly language CSUB for use on the HP-UX system. Topics covered are as follows:
If you have an assembly language CSUB file called
paw_file
located on a Pascal Workstation disk, it can
be copied over to your HP-UX system using the COPY command. For information
on how to do this, refer to the HP BASIC 6.2 Porting and Globalization
manual. However, to simplify things, the assembly language file named
paw_file
can be found in the HP-UX examples directory
called /usr/lib/rmb/demo
. You will be using this file
to learn how atrans works. The following listing shows the contents
of this file:
* Define some handy mnemonics
front equ a0 Pointer to the front half of the string
back equ a1 Pointer to the back half of the string
result equ a2 Pointer to a 16 bit INTEGER
return equ a3 The return address
temp equ d0 Used for calculations and comparisons
* Define the entry point
def palindrome
* Go for it. First unload the stack
palindrome equ *
movea.l (sp)+,return
movea.l (sp)+,result
movea.l (sp)+,front
addq.l #4,sp The dimentryptr is not used
* Get the current string length and use this to set up
* the front and back pointers. Remember, a BASIC string is
* a 16-bit integer followed by a packed array of characters.
clr.l temp
move.w (front),temp Get string length
addq.l #2,front The first character is always here
lea 0(front,temp),back Back points to last character+1
* Use the pre-increment and post-decrement of the address
* registers to compare characters and update pointers.
loop move.b -(back),temp Get next "back" character;
cmp.b (front)+,temp compare it to the "front";
bne.s false quit if there is a mismatch
cmpa front,back If "back" is still less than...
blt loop ...keep trying
true move.w #1,(result) Set it true
jmp (return)
false clr.w (result)
jmp (return)
end
The HP-UX command atrans is used to partially translate a Pascal Workstation assembly language program for use on the HP-UX system. The reason the translator partially translates the assembly program is there are symbol definition pseudo-ops and registers that cannot be used in your HP-UX assembly CSUB.
To test the atrans command on a Pascal Workstation assembly language
CSUB, copy the file called paw_file
to your current working
directory and execute the following command: atrans paw_file >
paw_file.s
This command redirects the output of atrans to the file called
paw_file.s
. The contents of your file should look like
this:
# Define some handy mnemonics
set front,%a0 #Pointer to the front half of the string
set back,%a1 #Pointer to the back half of the string
set result,%a2 #Pointer to a 16 bit INTEGER
set return,%a3 #The return address
set temp,%d0 #Used for calculations and comparisons
# Define the entry point
global palindrome
# Go for it. First unload the stack
set palindrome,.
movea.l (%sp)+,return
movea.l (%sp)+,result
movea.l (%sp)+,front
addq.l &4,%sp #The dimentryptr is not used
# Get the current string length and use this to set up
# the front and back pointers. Remember, a BASIC string is
# a 16-bit integer followed by a packed array of characters.
clr.l temp
move.w (front),temp #Get string length
addq.l &2,front #The first character is always here
lea 0(front,temp),back #Back points to last character+1
# Use the pre-increment and post-decrement of the address
# registers to compare characters and update pointers.
loop: move.b -(back),temp #Get next "back" character;
cmp.b temp,(front)+ #compare it to the "front";
bne.b false #quit if there is a mismatch
cmpa back,front #If "back" is still less than...
blt loop #...keep trying
true: move.w &1,(result) #Set it true
jmp (return)
false: clr.w (result)
jmp (return)
# end
Since atrans does not fully translate a Pascal Workstation assembly
program to code usable on the HP-UX system, you will have to manually complete
the translation of the assembly language program called
paw_file.s
. This section covers the changes you need
to make to the paw_file.s
file so you can create an object
code file out of it. When your file is completely translated, it should look
like this:
# Define some handy mnemonics
# Define the entry point
global _palindrome
_palindrome:
# Go for it. First unload the stack
movea.l (%sp)+,%a3
addq.l &4,%sp #The dimentryptr is not used
movea.l (%sp)+,%a0
movea.l (%sp)+,%a2
# Get the current string length and use this to set up
# the front (%a0) and back (%a1) pointers. Remember, a BASIC string is
# a 16-bit integer followed by a packed array of characters.
clr.l %d0
move.w (%a0),%d0 #Get string length
addq.l & 2,%a0 #The first character is always here
lea 0(%a0,%d0),%a1 #%a1 points to last character+1
# Use the pre-increment and post-decrement of the address registers
# to compare characters and update pointers.
loop: move.b -(%a1),%d0 #Get next "back" (%a1) character;
cmp.b %d0,(%a0)+ #compare it to the "front" (%a0);
bne.b false #quit if there is a mismatch
cmpa %a1,%a0 #If "back" is still less than...
blt loop #...keep trying
true: move.w & 1,(%a2) #Set it true
jmp (%a3)
false: clr.w (%a2)
jmp (%a3)
# end
Here are the changes that were made to the file called
paw_file.s
:
front |
replaced with %a0 |
back |
replaced with %a1 |
result |
replaced with %a2 |
return |
replaced with %a3 |
temp |
replaced with %d0 |
Lines 18 and 20 Before Exchange. | Exchanged Lines. |
---|---|
movea.l (%sp),%a2 movea.l (%sp),%a0
addq.l & 4,%sp |
addq.l & 4,%sp movea.l
(%sp),%a0 movea.l (%sp),%a2 |
global
pseudo-op's
identifier name. It should look like this: global
_palindrome
_palindrome
just under the
global
pseudo-op. Your label should look like this:
global _palindrome
_palindrome:
Note that all of the above changes are the types of changes that you will need to make to your Pascal Workstation assembly language programs and CSUBs when you translate them using the HP-UX command atrans.
To complete the creation of your assembly language CSUB and to test it, you need to complete these steps:
You will want to use the original BASIC program that you created on the BASIC
Workstation to test you assembly CSUB. To do this, use the COPY command.
For information on how to use the COPY command to transfer files to the HP-UX
operating system, refer to the HP BASIC 6.2 Porting and Globalization
manual. To save you time, there is a file named
PAL_PROG
located in the HP-UX examples directory called
(/usr/lib/rmb/demo
). The contents of the file are as
follows:
100 LOADSUB ALL FROM "PAL_DRO"
110 DIM Test$[80]
120 INTEGER Result
130 DISP "This is a test for palindromes."
140 WAIT 2
150 LINPUT "Enter a word and press [Return].",Test$
160 Palindrome(Test$,Result)
170 IF Result=1 THEN
180 PRINT "The word you entered is a palindrome."
190 ELSE
200 PRINT "The word you entered is not a palindrome."
210 END IF
220 DELSUB Palindrome
230 END
The above program when executed loads the PROG file called
PAL_DRO
which contains the CSUB called
Palindrome
. It then asks you to enter a word that can
be either a palindrome or a non-palindrome. A palindrome is a word or phrase
that reads the same backward or forward. The word you type in is passed as
a string to the palindrome
CSUB. The CSUB then returns
a 1 in the variable Result
if the word you entered is
a palindrome; otherwise, a 0 is returned. A message stating that the word
you entered is either a palindrome or not a palindrome is then displayed.
The remaining steps for completing your CSUB are the same as steps 4 through
7 for creating a Pascal CSUB. These steps can be found in the section "Steps
for Creating a Pascal CSUB" found in the chapter "Writing Pascal CSUBs."
Note that the stream file that you created on the Pascal Workstation, for
the original CSUB, can be copied over to the HP-UX system. This file, with
minor modifications, can then be used with the HP-UX rmbbuildc command
to create the PROG file that your BASIC/UX program will call. To use this
stream file, you would type a command similar to the following:
rmbbuildc <
paw_stream_file where paw_stream_file
is the modified Pascal Workstation stream file.