code:<pre style="font-size:x-small; font-family: monospace;"> org $400 CSC802 Coursework by [email protected]
move.l #$FFF0,sp Set the stack pointer
move.l #12,d0 Switch off echo
move.l #0,d1
trap #15
morsecode ds.b 16 Make room for morse codes and
lea morsecode,a0 fill the array with morse codes
move.b #-65,(a0)+ 0 ----- top 3 bits contain length
move.b #-66,(a0)+ 1 .---- bottom 5 bits contains 0
move.b #-68,(a0)+ 2 ..--- where there should be a .
move.b #-72,(a0)+ 3 ...-- and 1 where there should
move.b #-80,(a0)+ 4 ....- be a - but in reverse order
move.b #-96,(a0)+ 5 ..... for easy printing.
move.b #-95,(a0)+ 6 -....
move.b #-93,(a0)+ 7 --... ie the LSB of 7 is 1 because
move.b #-89,(a0)+ 8 ---.. it starts with a -
move.b #-81,(a0)+ 9 ----.
move.b #66,(a0)+ 10 A .- length -. <- note ordering
move.b #-127,(a0)+ 11 B -... A: 010 XXX10
move.b #-75,(a0)+ 12 C -.-.-
move.b #97,(a0)+ 13 D -.. if less than 5 bits is needed
move.b #32,(a0)+ 14 E . zeros are used for padding (X)
move.b #-124,(a0) 15 F ..-.
str ds.b 12 Make room for string + termination and padding
jsr readStr read a string from keyboard
jsr printStr print it (just to see it´s correct)
jsr printPlain print morse code in .- style
jsr printUpper print upper half of paper tape
jsr printLower print lower half of paper tape
exit move.b #9,d0 exit the program
trap #15
readStr lea str,a0 Reads a string into str
move.l #0,d2 use d2 as a counter
rsLoop cmp.b #8,d2 has the user entered 8 chars?
beq rsFinish then finish
move.b #5,d0 read one character into d1
trap #15
cmp.b #13,d1 is it a newline?
beq rsFinish then finish
rsCheckNum cmp.b #´0´,d1 is it a number (0-9)?
blt rsCheckChar if not check if it´s a char
cmp.b #´9´,d1
bgt rsCheckChar
bra rsValid it must be a number, goto valid
rsCheckChar cmp.b #´A´,d1 is it a char (A-F)?
blt rsLoop if not go to beginning of loop
cmp.b #´F´,d1
bgt rsLoop
bra rsValid it must be a char, goto valid
rsValid jsr print valid character: print it
move.b d1,(a0)+ store it in array
add.b #1,d2 and increase counter
bra rsLoop and repeat
rsFinish cmp.b #0,d2 did the user not enter any chars?
beq exit then exit
move.b #0,(a0) termintate string with null
jsr newLine print newline and return
rts
printStr lea str,a0 Prints the string stored in str as is
psLoop move.b (a0)+,d1 while (a0) != 0
cmp.b #0,d1
beq psReturn
jsr print print the character
bra psLoop continue loop
psReturn jsr newline print newline and return
rts
printUpper move.b #´o´,d2 Prints upper half of tape output
move.b #´ ´,d3 sets d2 & d3 since they´re used by
jsr printMorse printMorse to replace 0 and 1
rts
printLower move.b #´ ´,d2 Prints lower half of tape output
move.b #´o´,d3
jsr printMorse
rts
printPlain move.b #´.´,d2 Prints morse using dots and dashes
move.b #´-´,d3
jsr printMorse
rts
printMorse lea str,a0 Prints the morse code for the string str using
the content of d2 for . and d3 for -
pmLoop move.b (a0)+,d1 while (a0) != 0
cmp.b #0,d1
beq pmReturn
jsr charToIndex convert d1 from char to index of morsecodes
jsr printCode print the code
jsr printSpace print a space character
bra pmLoop continue loop
pmReturn jsr newline print newline and return
rts
printCode lea morsecode,a1 Prints the code of morsecode[d1] note that this
add.w d1,a1 routine uses a1 since a0 is used by printMorse
move.b (a1),d7 use d7 for length (only top 3 bits)
lsr.b #5,d7 shift out all but the top 3 bits
move.b (a1),d6 use d6 for code
move.b #0,d5 use d5 for counter
pcLoop cmp d5,d7 while d5 != d7
beq pcReturn
btst d5,d6 test bit d5
beq pcDot
bra pcDash
pcDot move.b d2,d1 print content of d2 if bit was 0
jsr print
bra pcStep
pcDash move.b d3,d1 print content of d3 if bit was 1
jsr print
bra pcStep
pcStep add.b #1,d5 d5++
bra pcLoop continue loop
pcReturn rts
charToIndex cmp.b #65,d1 Overwrite the char in d1 with it´s index
bge ctiChar in the array morsecode (A-F, 0-9 is assumed)
bra ctiNumber
ctiChar sub.b #55,d1 remove 55 from the ASCII code of the char
rts to get its index in the array.
ctiNumber sub.b #48,d1 remove 48 from the ASCII code of the number
rts to get its index.
print move.b #6,d0 Print character in d1
trap #15
rts
printSpace move.b #´ ´,d1 Print a space character
jsr print
rts
newline move.b #13,d1 Print a newline
jsr print
move.b #10,d1
jsr print
rts
end $400</pre>