Hey Stackoverflow I was going over some example code our professor has left us to study with, and I've had some problems understanding what some of the codes mean and it doesnt help that some of his comments are vague. the first is R3,R1,0; check for end of line, the second thing I dont get is really the logic behind the beginning of the placeolnul, and lastly the .fill values for negeol which seem oddly specific but i have no idea why. if you could really help me with those issues it would really help me understand the code alot better.
.orig x3000
getstring:
lea r0,prompt ;get string prompt
puts
ld r1,negeol ;to test end of line
lea r2,rdbuff ;prep to read string
rdloop:
getc ;get string char
out
str r0,r2,0 ;store it
add r3,r1,r0 ;check for end of line
brz placeeolnul ;if so process
add r2,r2,1 ;ready for next char
br rdloop ;get it
placeeolnul:
and r0,r0,0 ;overwrite eol with
str r0,r2,0 ;nul
lea r1,rdbuff ;get address for len
jsr strlen ;get length
add r0,r0,0 ;if 0
brz quit ;then prog finished
trap xfc ;print length
lea r0,colon ;print colon
puts
lea r0,eol ;print lf
puts
br getstring ;go again
quit
halt
prompt: .stringz "Enter a string:"
eol: .fill x000d ; or x000a
.fill x0000
negeol: .fill xfff3 ; or xfff6
colon: .fill x003a
rdbuff .blkw 80
; length subroutine
strlen:
and r0,r0,0 ;counter for length
st r2,saveX2 ;save regs used
st r3,saveX3
add r2,r1,0 ;copy of string addr
cloop:
ldr r3,r2,0 ;get char
brz exit ;check for nul
add r0,r0,1 ;incr counter
add r2,r2,1 ;go to next char
br cloop ;process it
exit:
ld r2,saveX2 ;restore used regs
ld r3,saveX3
ret
saveX2: .blkw 1
saveX3: .blkw 1
.end