I was wondering if anyone would like to comment on my assembly assignment.
I have finished it, and wanted ideas on optimising.
I have already submitted it to my teacher, but would love to know any good ideas on how to make it better.
Thanks.
x
H1 Machine-Level
Simulator Version 5.0 Copyright (c) 2005 A. J. Dos Reis
Code:
;DISCRIPTION:
;(1) Reads user inputed string Max 20 Characters
;(2) Analyses it to see if a palindrome was entered.
;////////////////////////////////
;/////////////main///////////////
;////////////////////////////////
IDeclareRoShamBo:
call acquireString ;call to acquireString module
call stringCount ;call to stringCount module
call palindrome ;call to palendrome module
error: ;early exit for pelendrome failure
halt ;end of program
Done:
;////////////////////////////////
;/////function acquireString/////
;////////////////////////////////
acquireString:
ldc '\n' ;load newline into ac
aout ;print newline to screen
ldc msg1 ;load message into ac
sout ;print message
ldc inbuf ;load address of buffer
sin ;read in string
ldc '\n' ;load newline into ac
aout ;print newline to screen
ldc inbuf ;load address of buffer
sout ;print newline to screen
ret
;////////////////////////////////
;/////function stringCount///////
;////////////////////////////////
stringCount:
loop1: ;loop label
ld count ;load counter
add @1 ;add 1 to counter
st count ;store counter
ldc inbuf ;load address of buffer
add count ;increment address
ldi ;load value stored at address
jnz loop1 ;loop if not zero
ret
;/////////////////////////////////
;/////function palindrom//////////
;/////////////////////////////////
palindrome:
ld count ;load count
sub @1 ;subtract 1 from count
st bindex ;store as back index
loop3: ;analysis loop
ldc inbuf ;load address of inbuf
add bindex ;add backward decrement to address
ldi ;load value pointed to
st testValue1 ;store value in test variable
ldc inbuf ;load address of inbuf
add findex ;add forward increment to address
ldi ;load value pointed to
st testValue2 ;store value in test variable
sub testValue1 ;subtract testValue1 from testValue2
st testResult ;store result
jnz notPalin ;if value is 0 execute notPalin
call crossIncr ;call crossIncr to move pointer addresses
ld bindex ;load bindex to determine more analysis
jzop loop3 ;loop if analysis is not complete
call isPalindrome ;call function isPalindrome
ret
;////////////////////////////////
;///Function crossIncr///////////
;////////////////////////////////
crossIncr:
ld findex ;load findex to ac
add @1 ;increment findex
st findex ;store findex
ld bindex ;load bindex to ac
sub @1 ;decrement bindex
st bindex ;store bindex
ret
;////////////////////////////////
;///Function notPalin////////////
;////////////////////////////////
notPalin:
ldc '\n' ;load newline into ac
aout ;print newline to screen
ldc msg2 ;load message into ac
sout ;print message
ldc '\n' ;load newline into ac
aout ;print newline to screen
ja error
;////////////////////////////////
;///Function isPalindrome////////
;////////////////////////////////
isPalindrome:
ldc '\n' ;load newline into ac
aout ;print newline to screen
ldc msg3 ;load message into ac
sout ;print message
ldc '\n' ;load newline into ac
aout ;print newline to screen
ret
;////////////////////////////////
;//////////data area/////////////
;////////////////////////////////
inbuf: dw 20 dup 0
bindex: dw 0
findex: dw 0
@1: dw 1
count: dw 0
testValue1: dw 0
testValue2: dw 0
testResult: dw 0
msg1: dw "Enter String: "
msg2: dw "String is not palindrome"
msg3: dw "String is palindrome"