Hi im new here and there's this small error with my code.
to summarize the whole thing it basically allows you to input '1's and '0's only while it counts the number of '1's , '0's and the total input count.
1)its almost done but how do i get rid of that weird symbol at the beginning of every input??
2)and also, after each input the '1's and '0's will be stored starting from address $2000, eg: input = 101, so $2000 = 1 , $2001 = 0 , $2002=1.
I cant seem to clear the addresses when the program loops without messing up the loop itself
other than the 2 minor problems stated above, code works perfectly fine
here's the current working code
Code:
START: ORG $1000 ; first instruction of program
move.l #$7ffe,a7 ; initialise stack pointer
move.b #0,d1 ; clear d1 for safety
move.b #12,d0 ; turn off keyboard echo
trap #15
move.l #reserve,a2 ; save memory location of length to a2
*-----------input message--------
begin move.l #inmess,a0
move.b #14,d0
trap #15
*------------input-----------
loop move.l #0,a0 ; clears a0 which stores inmess
move.b #5,d0
trap #15 ;initiates trap task 5, reads a character from keyboard into d1.l
cmp.b #'1',d1
beq store1
cmp.b #'0',d1
beq store0
cmp.b #cr,d1 ;compares d1 to 'enter' aka CR
beq end1 ;end1 begins printing the result
bra invalid
*-----------error input message--------
invalid lea error,a1 ;using a1 to store strings from now on
move.b #14,d0
trap #15
clr.l d1 ;clears d1 again to accept new input again
bra loop
*-----------storing 0s----------
store0 move.b d1,(a2)+ ;a2 is the reserve, stores the '0's into reserve $2000+
add.b #1,d2 ;d2 is the number of '0's
move.b #6,d0
trap #15
bra loop
*------------storing 1s--------
store1 move.b d1,(a2)+ ;same as above, but stores the '1's instead
add.b #1,d3 ;d3 is used to store the number of '1's
move.b #6,d0
trap #15
bra loop
*-----------print line1 = 'there are (no. of zero)'----------
end1 move.l #0,a1 ;clear a1 so next string can be stored
move.l #line1,a1 ;store line1 into a1
move.b #14,d0
trap #15
clr.l d1 ;clears d1 for safety
move.b d2,d1 ;moves the total no. of '0's into d1 to be read
move.b #3,d0
trap #15
bra end2
*-----------print line2 = 'zero and +(no. of 1)'-----------
end2 move.l #0,a1 ;again, clearing for safety
move.l #line2,a1
move.b #14,d0
trap #15
clr.l d1 ;clears d1 to make way for d3
move.b d3,d1 ;d3 which is the total no. of '1's is moved to d1
move.b #3,d0
trap #15
bra end3
*---------print line3 = '+ one in the input etc'--------
end3 move.l #0,a1
move.l #line3,a1
move.b #14,d0
trap #15
move.b d2,d4 ;moving d2 to d4, d4 acts as the total of '1's and '0's
add.b d3,d4 ;by adding d3 to d4, d4 now houses the total count of '1's and '0's
clr.l d1 ;clear d1 for safety
move.b d4,d1 ;move d4 to d1 so trap can display value
move.b #3,d0
trap #15
bra again
*----------continuation prompt---------
again move.l #0,a1 ;clearing to move msg 'cont' into a1
move.l #cont,a1 ;continuation message
move.b #14,d0
trap #15
clr.l d1 ;clearing all the previously used registers to prepare for the next loop
clr.l d2
clr.l d3
clr.l d4
move.l #0,a0
move.l #0,a1
move.b #5,d0
trap #15
cmp.b #'Y',d1
beq begin ;loops to beginning again
cmp.b #'Q',d1
beq close ;ends program
bra again
*---------end program-------------
close MOVE.B #9,D0
TRAP #15 ; halt simulator
* Variables and Strings
ORG $2000
reserve ds.b 200
cr equ $0d
lf equ $0a
ORG $3000
inmess dc.b 'Input 1 or 0',cr,lf,0
error dc.b cr,lf,'only 1 and 0 accepted. Please try again',cr,lf,0
line1 dc.b cr,lf,'There are ',0
line2 dc.b ' "zero" and ',0
line3 dc.b ' "one" in the input and total input string is ',0
cont dc.b cr,lf,'Do you wish to continue? (Y = yes / Q = Quit)',cr,lf,0
END START ; last line of source