1 Replies - 362 Views - Last Post: 21 May 2017 - 11:27 PM

#1 BananaSlug12321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-May 17

I am creating two arrays, one with a encoded message and one decoded

Posted 21 May 2017 - 05:45 PM

In LC3. Each subroutine works seperately but when I put them together with the main code I'm getting 'label' cannot be represented in 9-bit offset in the second assembler's check. I am very lost and don't really know why it's not working, if someone could help soon that would be great.

.ORIG x3000

	AND R0, R0, #0	
	AND R1, R1, #0
	AND R2, R2, #0	
	AND R3, R3, #0
	AND R4, R4, #0	
	AND R5, R5, #0
	AND R6, R6, #0
	AND R7, R7, #0

MAIN
	LDI R0, INITS
	PUTS				;WELCOMES USER
	AND R0, R0, #0	

MAIN1	LDI R0, INITQ			;ASKS FOR E D OR X
	PUTS
	AND R0, R0, #0

	LD R1, NEG88			
	LDI R2, CRYPTIONSIGN		;LOADS CRYPTIONSIGN ADDRESS 
	GETC 				;STORES E D OR X INTO R0
	ADD R1, R1, R0			;SUBTRACTS 88 FROM USER INT TO CHECK IF IT WAS X FOR EXIT
	BRz EXITING

	AND R1, R1, #0	

	STR R0, R2, #0			;STORES D OR E IN CRYPTIONSIGN ADDRESS
	AND R2, R2, #0
	AND R0, R0, #0
	
	LDI R0, CIPHER_Q		;AKS FOR AND STORES IN R0 HOW MUCH THE PROGRAM WILL BE CIPHERED BY
	PUTS
	AND R0, R0, #0
	GETC

	LDI R1, CIPHER			;LOADS ADDRESS OF THE CIPHER TO STORE CIPHER NUM INTO THAT ADDRESS
	STR R0, R1, #0
	
	AND R1, R1, #0
	AND R0, R0, #0

	LDI R0, STRING_Q
	PUTS				;PROMPTS USER FOR STRING THEY WANT ENCRYPTED OR DECRYPTED

LOPO	AND R0, R0, #0
	AND R2, R2, #0

	GETC 
	ADD R0, R0, #-10		;GETS CHAR FROM USER AND CHECKS IF ENTER IS PRESSED TO STOPPED STORING
	BRz POSTINPUT

	ADD R0, R0, #10			;ADDS BACK 10 FROM CHECK
	ADD R1, R1, R3			;ADDS R1(COLUMN NUM) TO R3(COUNTER) ((R2= ROW ALWAYS EQUALS ZERO HERE))
	ADD R3, R3, #1			;INCREMENT COUNTE
	JSR STORE 			;GOES TO STORE THE VALUE
			
	BRnzp LOPO			;RETURNS FROM STORE HERE, AND GOES BACK INTO LOOP
	
POSTINPUT
	AND R0, R0, #0
	AND R1, R1, #0
	AND R2, R2, #0
	
	LDI R1, CHARCOUNT
	STR R3, R1, #0			;STORES THE NUMBER OF CHARS USER ENTERED
	
	AND R1, R1, #0
	AND R2, R2, #0			;INITS VALUES

	LD R1, CRYPTIONSIGN		;LOADS THE CRYPTIONSIGN E OR D INTO R1
	LD R2, NEG68			
	ADD R2, R2, R1			;SUBTRACTS ASCII VAL FOR D FOR CHECK
	BRz DECC
	BRnp ENCC

DECC	
	AND R1, R1, #0
	AND R2, R2, #0	
	AND R3, R3, #0
	LD R3, CHARCOUNT		;LOADS THE CHAR COUNT USER ENTERED AND ADDS ONE FOR CORRECT COUNT PURPOSES
	ADD R3, R3, #1

ALOOP	ADD R3, R3, #-1			;SUBS AND CHECKS IF WE WENT THRU THE AMOUNT OF LETTERS USER ENTERED
	BRz POSTBLOCK2
	JSR LOAD 			;LOADS VAL AT (R1,R2)
	JSR DECRYPT			;DECRYPTS CHAR STORED AT THAT SPOT 
	LD R2, POS1			;LOADS 1 IN AS R2 FOR SECOND BLOCK
	JSR STORE			;STORES DECRYPTED (R1,R2)
	ADD R1, R1, #1			;INCREMENTS COLUMN SPECIFICATION
	BRnzp ALOOP			;BACK TO LOOP
		
ENCC 
	AND R1, R1, #0
	AND R2, R2, #0	
	AND R3, R3, #0
	LD R3, CHARCOUNT		;LOADS THE CHAR COUNT USER ENTERED AND ADDS ONE FOR CORRECT COUNT PURPOSES
	ADD R3, R3, #1

BLOOP	ADD R3, R3, #-1			;SUBS AND CHECKS IF WE WENT THRU THE AMOUNT OF LETTERS USER ENTERED
	BRz POSTBLOCK2
	JSR LOAD 			;LOADS VAL AT (R1,R2)
	JSR ENCRYPT			;ENCRYPTS CHAR STORED AT THAT SPOT 
	LD R2, POS1			;LOADS 1 IN AS R2 FOR SECOND BLOCK
	JSR STORE			;STORES ENCRYPTED (R1,R2)
	ADD R1, R1, #1			;INCREMENTS COLUMN SPECIFICATION
	BRnzp BLOOP			;BACK TO LOOP

POSTBLOCK2

	AND R0, R0, #0	
	AND R1, R1, #0
	AND R2, R2, #0	
	AND R3, R3, #0
	AND R4, R4, #0	
	AND R5, R5, #0
	AND R6, R6, #0
	AND R7, R7, #0

	JSR PRINT_ARRAY

CLOOP
	LD R1, NEG100
	ADD R1, R1, R2
	BRz MOBIOUS

	LEA R1, ARRAY
	ADD R1, R1, R2
	STR R3, R1, #0
	ADD R2, R2, #1
	BRnzp CLOOP

MOBIOUS 
	AND R1, R1, #0

	LEA R2, R1_ORIG
	STR R1, R2, #0

	LEA R2, R2_ORIG
	STR R1, R2, #0

	LEA R2, R3_ORIG
	STR R1, R2, #0

	LEA R2, R4_ORIG
	STR R1, R2, #0

	LEA R2, CRYPTIONSIGN
	STR R1, R2, #0

	LEA R2, CIPHER
	STR R1, R2, #0

	LEA R2, CHARCOUNT
	STR R1, R2, #0

	LEA R2, R0_ORIG
	STR R1, R2, #0

EXITING
	LEA R0, BYE
	PUTS

;--------------------------------------------------------------------
;		STORE SUBROUTINE
;INPUTS:
;	R0=CHAR_TO_STORE(ASCII VAL), R1=COL (0-49), R2=ROW(0 or 1) 
;
;OUTPUTS:
;	NONE
;
;THIS SUBROUTINE CHANGES CIPHER_ARRAY[R1,R2] TO THE CONTENTS OF R0
;---------------------------------------------------------------------

STORE 
	ST R0, R0_ORIG 			;Stores initial registers 
	ST R1, R1_ORIG
	ST R2, R2_ORIG 
	
	ADD R2, R2, #-1			;We check to see if we are loading from the TOP OR BOTTOM block 
	BRz BLKUPPER1
	BRnp BLKLOWER1

BLKUPPER1
	AND R2, R2, #0 
	ADD R2, R2, #15
	ADD R2, R2, #15
	ADD R2, R2, #15
	ADD R2, R2, #5			;We add 50 to R2 to reach the the second half(manipulated string) of the block
	BRnzp #1			;Skip one line so we don't have a false R2 value

BLKLOWER1
	ADD R2, R2, #1			;This line adds the one subtracted for the row check if we are in the unmanopulated block

	LEA R3, ARRAY			;Loads address of Array
	ADD R3, R3, R2			;Adds the 50 or 0 for row specifics
	ADD R3, R3, R1			;Adds (0-50) for column specifics
	STR R0, R3, #0 			;Stores contents in R0 into address of R3
	LD R0, R0_ORIG 			;Loads back initial values then returns
	LD R1, R1_ORIG
	LD R2, R2_ORIG  
	RET
;-----------END OF STORE SUBROUTINE-------------






;-----------------------------------------------
;		LOAD SUBROUTINE
;INPUTS:
;	R1=COL(0-49), R2=ROW(0-1)
;
;OUTPUTS:
;	R0=CONTETS OF CIPHER_ARRAY[R1,R2]
;	
;	WILL RETURN ALL BUT R0 BACK TO THEIR VALUES BEFORE CALL 
;-----------------------------------------------

LOAD
	ST R1, R1_ORIG			;R1= COL(0-49) & R2= ROW(0-1) 
	ST R2, R2_ORIG
			
	ADD R2, R2, #-1			;We check to see if we are loading from the encrypted or decrypted block
	BRz BLKUPPER
	BRnp BLKLOWER
	
BLKUPPER	
	AND R2, R2, #0 			;We add 50 to R2 to reach the the second half(manipulated string) of the block
	ADD R2, R2, #15
	ADD R2, R2, #15
	ADD R2, R2, #15
	ADD R2, R2, #5
	BRnzp #1			;Skip the next line so we don't have a false R2 value

BLKLOWER
	ADD R2, R2, #1			;This adds back the 1 that was subtracted for the check
	
	LEA R3, ARRAY			;Load address of Array
	ADD R3, R3, R2			;ADD either 50 or 0 for row
	ADD R3, R3, R1			;ADD column so we are at correct array address	
	LDR R0, R3, #0 			;LOAD value at that address into R0
	LD R1, R1_ORIG			;Load initial R1 and R2 values back and Return
	LD R2, R2_ORIG
	RET
;-----------END OF LOAD SUBROUTINE-------------






;--------------------------------------------------------------------
;		PRINT_ARRAY SUBROUTINE
;INPUTS:
;	NONE
;
;OUTPUTS:
;	NONE
;
;THIS SUBROUTINE DIPLAYS THE ENCRYPTED ARRAY TO THE CONSOLE
;---------------------------------------------------------------------
PRINT_ARRAY

	AND R0, R0, #0
	AND R1, R1, #0
	AND R2, R2, #0
	AND R3, R3, #0
	AND R4, R4, #0
	AND R5, R5, #0
	AND R6, R6, #0
	
	LD R1, CRYPTIONSIGN 			;LOADS IN OUTSIDE D OR E
	LD R2, NEG68				;LOADS VAL -68 FOR CHECK OF D OR E			
	
	ADD R2, R2, R1				;CRYPTIONSIGN VAL IS SUBTRACTED FROM 68(D)
	BRz DECRYPTION				;IF IT IS ZERO WE DECRYPT
	BRnp ENCRYPTION				;IF IT IS OTHER WE ENCRYPT

DECRYPTION

	AND R1, R1, #0
	AND R2, R2, #0				;INITING PAST USED VALUES
	
	LEA R0, ENCRYPTIONM			;LOADING MESSAGE FOR ENCRYPTED
	PUTS	

DLOOP1
	
	AND R0, R0, #0
	LD R1, NEG50				;LOADS VAL -50 INTO R1
	ADD R1, R1, R2				;SUBTRACTS 50 FROM COUNTER TO SEE IF WE ARE DONE LOOPING
	BRz DDONELOOPIN1

	LEA R3, ARRAY				;LOADING THE ADDRES OF THE ARRAY INTO R1
	ADD R3, R3, R2				;ADDS THE COUNTER TO THE ADDRESS TO SHIFT ADDRESS SPOTS
	LDR R0, R3, #0				;LOADS CONTENTS OF ADDRESS OF R3 INTO R0
	OUT					;PRINTS DATA ADDRESS
	ADD R2, R2, #1				;INCREMENT COUNTER
	BRnzp DLOOP1 
	
DDONELOOPIN1

	AND R1, R1, #0
	AND R2, R2, #0
	AND R3, R3, #0
	
	LEA R0, SPACE
	PUTS	
	AND R0, R0 #0				;ADDS AN ATHESTETICALLY SPACE BETWEEN D/E

	LEA R0, DECRYPTIONM			;LOAD DECRYPTON MESSAGE INTO R0
	PUTS					;OUTPUT
	AND R0, R0, #0	
	
DLOOP2
	AND R0, R0 #0
	LD R1, NEG50				;SET THE ANTI-COUNTER TO SUB FROM FINAL COUNTEER
	ADD R1, R1, R2				;SUBTRACT FROM COUNTER TO SEE IF WE'RE DONE LOOPING
	BRz DDONELOOPIN2
	
	LEA R3, ARRAY				;LOAD ADDRESS OF R3 INTO ARRAY
	ADD R3, R3, R2				;ADD COUNTER TO ARRAY TO GET SPECIFIC ADDRESS
	LDR R0, R3, #0				;LOAD REGISTER CONTENTS AT THAT ADDRESS SPECIFIED
	OUT
	ADD R2, R2, #1				;INCREMENT COUNTER
	BRnzp DLOOP2				;LOOP

DDONELOOPIN2
	LD R0, R0_ORIG				;LOAD IN PREVIOUS VALUES IF ANY THEN RETURN
	LD R1, R1_ORIG
	LD R2, R2_ORIG
	RET
;--------------

ENCRYPTION

	AND R1, R1, #0				;INITING PAST USED VALUES
	AND R2, R2, #0

	LEA R0, DECRYPTIONM			;LOADING MESSAGE FOR DECRYPTIED
	PUTS					

ELOOP1
	AND R0, R0, #0
	LD R1, NEG50				;LOADS VAL -50 INTO R1
	ADD R1, R1, R2				;SUBTRACTS 50 FROM COUNTER TO SEE IF WE ARE DONE LOOPING
	BRz EDONELOOPIN1

	LEA R3, ARRAY				;LOADING THE ADDRES OF THE ARRAY INTO R1
	ADD R3, R3, R2				;ADDS THE COUNTER TO THE ADDRESS TO SHIFT ADDRESS SPOTS
	LDR R0, R3, #0				;LOADS CONTENTS OF ADDRESS OF R3 INTO R0
	OUT					;PRINTS DATA ADDRESS
	ADD R2, R2, #1				;INCREMENT COUNTER
	BRnzp ELOOP1

EDONELOOPIN1
	AND R0, R0, #0
	AND R1, R1, #0
	AND R2, R2, #0
	AND R3, R3, #0
	
	LEA R0, SPACE
	PUTS	
	AND R0, R0 #0				;ADDS AN ATHESTETICALLY SPACE BETWEEN D/E
	
	LEA R0, ENCRYPTIONM			;LOADING MESSAGE FOR ENCRYPTION
	PUTS
	AND R0, R0, #0	
ELOOP2
	AND R0, R0, #0
	LD R1, NEG50				;SET THE ANTI-COUNTER TO SUB FROM FINAL COUNTEER
	ADD R1, R1, R2				;SUBTRACT FROM COUNTER TO SEE IF WE'RE DONE LOOPING
	BRz EDONELOOPIN2
	
	LEA R3, ARRAY				;LOAD ADDRESS OF R3 INTO ARRAY
	ADD R3, R3, R2				;ADD COUNTER TO ARRAY TO GET SPECIFIC ADDRESS
	LDR R0, R3, #0				;LOAD REGISTER CONTENTS AT THAT ADDRESS SPECIFIED
	OUT
	ADD R2, R2, #1				;INCREMENT COUNTER
	BRnzp ELOOP2				;LOOP

EDONELOOPIN2
	LD R0, R0_ORIG				;LOAD IN PREVIOUS VALUES IF ANY THEN RETURN
	LD R1, R1_ORIG
	LD R2, R2_ORIG
	RET

;---------------------------------------------------------------------------------------------------------------------------------------------

ENCRYPT
	ST R0, R0_ORIG		
	
	AND R1, R1, #0
	AND R2, R2, #0	
	AND R3, R3, #0
	AND R4, R4, #0	
	AND R5, R5, #0
	AND R6, R6, #0

	LD R2, NEG65			;VALUE OF -65 IN R2 FOR FUTURE CHECK OF UC
	LD R4, NEG26			; VALUE OF -26 IN R4 FOR FUTURE COUNTER
	ADD R0, R0, R2			;SUBTRACT 65 FROM R3(USER CHAR)

	BRz UC				; THIS WOULD BE (A) AND SHOULD BRANCH TO UPPERCASE(UC)
	BRn REGCHAR			; IF THE CHAR-65 IS NEG IT CANNOT BE A LETTER AND IS SENT TO NOT BE CHANGED


LOOPUC					;LOOP SUBTRACTING ONE CHECKING FOR UPPER CHARS WHERE R0=0 DECIDES WHERE TO BRANCH TO
	LD R4, NEG26			
	ADD R4, R1, R4			; SUBTRACTING 26 FROM COUNTER TO SEE IF WE'VE LOOPED THRU THE WHOLE CAPITAL ALPHABET
	BRzp FOO			;IF WE HAVE LOOPED THRU ALL UC LETTERS, WE GO CHECK FOR LC
	ADD R1, R1, #1			; ADDING 1 TO COUNTER
	ADD R3, R3, #-1			;SUBTRACTING 1 FROM ASCII VALUE OF LETTER
	BRz UC
	BRnzp LOOPUC

FOO
	ADD R3, R3, #-7
	BRz LC				;THESE LINES JUMP FROM ASCII 'Z' TO 'a' THEN BR TO LC IF a IS PRESENT
	AND R1, R1, #0
LOOPLC	
	LD R4, NEG26			;LOADS -26 VALUE INTO R4
	ADD R4, R4, R1			;SUBTRACTS 26 FROM R1(COUNTER)
	BRzp REGCHAR			;IF FULLY LOOPED THROUGH LC ASCII #S, IT SHOULD NOT BE MODIFIED
	ADD R1, R1, #1			;ADD ONE TO COUNTER 
	ADD R3, R3, #-1			;DECREASE ONE FROM R3(WAS USER CHAR #)
	BRz LC				;IF WE REACH ZERO WE FOUND A LOWERCASE CHAR
	BRnzp LOOPLC			;ELSE WE GO BACK INTO THE LOOP

UC
	AND R2, R2, #0			;INITIALIZNG NUMS FOR USE
	AND R3, R3, #0
	AND R4, R4, #0

	LD R1, CIPHER			;LOADS INITIAL R1(USER'S KEY)	
	LD R0, R0_ORIG			;LOADS INTITIAL R0(USER'S ASCII #)

LOOPUC1

	LD R2, NEG91			;LOADING VAL -91 INTO R2 AS THE ENCRYPTION UC BOUND 

	ADD R0, R0, #1			;ADDS ONE TO R0 TO ENCRYPT DEEPER
	ADD R0, R0, R2			;CHECKS IF R0 PASSED 'Z'
	BRnp #4				;IF ASCII CHAR IS ANYTHING BUT 91, SURPASS NEXT 3 LINES

	LD R2, POS65			;LOAD VAL 65 INTO R2
	AND R0, R0, #0			
	ADD R0, R0, R2			;INITIALIZE R0 THEN ADD 65 TO IT 
	BRnzp #2	

	LD R2, POS91			;PUTTING 91 INTO R2
	ADD R0, R0, R2			;ADDS NINETY ONE BACK TO R0 

	ADD R1, R1, #-1			;SUBTRACT FROM KEY
	BRz DONE			;IF KEY IS 0, WE ARE DONE SHIFTING CHAR
	BRnzp LOOPUC1			;ELSE WE WILL GO BACK INTO THE LOOP

LC 
	AND R2, R2, #0			;INITIALIZNG NUMS FOR USE
	AND R3, R3, #0
	AND R4, R4, #0

	LD R1, R1_ORIG			;LOADS INITIAL R1(USER'S KEY)	
	LD R0, R0_ORIG			;LOADS INTITIAL R0(USER'S ASCII #)
	
LOOPLC1
	LD R2, NEG123			;LOADS VAL -123 INTO R2
	ADD R0, R0, #1			;ADDS ONE TO ENCRYPT DEEPER
	ADD R0, R0, R2			;CHECKS TO SEE IF WE SURPASSED 'z' BY SUBTRACTING 123
	BRnp #4				;IF WE DID WE DON'T SKIP 4 LINES
	
	LD R2, POS97
	AND R0, R0, #0				
	ADD R0, R0, R2			;ADDS ASCII VALUE FOR 'a' INTO R0
	BRnzp #2			;SKIP LINES USED FOR NOT PASSED 'z'

	LD R2, POS123
	ADD R0, R0, R2
	
	ADD R1, R1, #-1
	BRz DONE
	BRnzp LOOPLC1

;---------------------------------------------------------------------------------------------------------------------------------------------------

;lmao  :'////

;--------------------------------------------------------------------------------------------------------------------------------------------


DECRYPT
	ST R0, R0_ORIG		

	AND R1, R1, #0
	AND R2, R2, #0
	AND R3, R3, #0
	AND R4, R4, #0
	AND R5, R5, #0
	AND R6, R6, #0

	LD R1, NEG65			;VALUE OF -65 IN R2 FOR FUTURE CHECK OF UC
	ADD R0, R0, R1			;SUBTRACT 65 FROM R3(USER CHAR)

	BRz UC12			; THIS WOULD BE (A) AND SHOULD BRANCH TO UPPERCASE(UC)
	BRn REGCHAR			; IF THE CHAR-65 IS NEG IT CANNOT BE A LETTER AND IS SENT TO NOT BE CHANGED

LOOPUC3					;LOOP SUBTRACTING ONE CHECKING FOR UPPER CHARS WHERE R0=0 DECIDES WHERE TO BRANCH TO
	LD R4, NEG26			
	ADD R4, R1, R4			; SUBTRACTING 26 FROM COUNTER TO SEE IF WE'VE LOOPED THRU THE WHOLE CAPITAL ALPHABET
	BRzp FOO1			;IF WE HAVE LOOPED THRU ALL UC LETTERS, WE GO CHECK FOR LC
	ADD R1, R1, #1			; ADDING 1 TO COUNTER
	ADD R3, R3, #-1			;SUBTRACTING 1 FROM ASCII VALUE OF LETTER
	BRz UC12
	BRnzp LOOPUC3

FOO1
	ADD R3, R3, #-6
	BRz LC111			;THESE LINES JUMP FROM ASCII 'Z' TO 'a' THEN BR TO LC IF a IS PRESENT
	AND R1, R1, #0

LOOPLC3	
	LD R4, NEG26			;LOADS -26 VALUE INTO R4
	ADD R4, R4, R1			;SUBTRACTS 26 FROM R1(COUNTER)
	BRzp REGCHAR			;IF FULLY LOOPED THROUGH LC ASCII #S, IT SHOULD NOT BE MODIFIED
	ADD R1, R1, #1			;ADD ONE TO COUNTER 
	ADD R3, R3, #-1			;DECREASE ONE FROM R3(WAS USER CHAR #)
	BRz LC111				;IF WE REACH ZERO WE FOUND A LOWERCASE CHAR
	BRnzp LOOPLC3			;ELSE WE GO BACK INTO THE LOOP

UC12
	AND R0, R0, #0			;INITIALIZNG NUMS FOR USE
	AND R1, R1, #0

	LD R1, CIPHER			;LOADS INITIAL R1(USER'S KEY)	
	LD R0, R0_ORIG			;LOADS INTITIAL R0(USER'S ASCII #)

LOOPUC11

	LD R2, NEG64			;LOADING VAL -64 INTO R2 AS THE DECRYPTION UC BOUND 

	ADD R0, R0, #-1			;SUBS ONE TO R0 TO DECRYPT DEEPER
	ADD R0, R0, R2			;CHECKS IF R0 PASSED 'A'
	BRnp #4				;SURPASS NEXT 4 LINES IF WE PASSED 'A'

	LD R2, POS90			;LOAD VAL 90 INTO R2
	AND R0, R0, #0			
	ADD R0, R0, R2			;INITIALIZE R0 THEN ADD 90 TO IT 
	BRnzp #2	

	LD R2, POS64			;PUTTING 64 INTO R2
	ADD R0, R0, R2			;ADDS 64 BACK TO R0 

	ADD R1, R1, #-1			;SUBTRACT FROM KEY
	BRz DONE			;IF KEY IS 0, WE ARE DONE SHIFTING CHAR
	BRnzp LOOPUC11			;ELSE WE WILL GO BACK INTO THE LOOP

LC111 
	AND R2, R2, #0			;INITIALIZNG NUMS FOR USE
	AND R3, R3, #0
	AND R4, R4, #0

	LD R1, CIPHER			;LOADS INITIAL R1(USER'S KEY)	
	LD R0, R0_ORIG			;LOADS INTITIAL R0(USER'S ASCII #)
	
LOOPLC13
	LD R2, NEG96			;LOADS VAL -96 INTO R2
	ADD R0, R0, #-1			;SUBS ONE TO DECRYPT DEEPER
	ADD R0, R0, R2			;CHECKS TO SEE IF WE SURPASSED 'a' BY SUBTRACTING 96
	BRnp #4				;IF WE DID WE DON'T SKIP 4 LINES
	
	LD R2, POS122
	AND R0, R0, #0				
	ADD R0, R0, R2			;ADDS ASCII VALUE FOR 'a' INTO R0
	BRnzp #2			;SKIP LINES USED FOR NOT PASSED 'z'

	LD R2, POS96			
	ADD R0, R0, R2			;ADDS 96 BACK TO R0
	
	ADD R1, R1, #-1
	BRz DONE
	BRnzp LOOPLC13
;---------------------------------------------------------------------------------------------------------------------------------------------------
REGCHAR 
	AND R1, R1, #0
	LEA R0, R0_ORIG
	LDR R0, R0, #0

DONE 
	RET				;R0 IS DESIRED VALUE, WE RETURN
;---------------------------------------------------------------------------------------------------------------------------------------------------
HALT 

POS122				.FILL #122
NEG96				.FILL #-96
NEG91				.FILL #-91
POS96				.FILL #96
NEG100				.FILL #-100
NEG50 				.FILL #-50
NEG88				.FILL #-88
NEG68				.FILL #-68
POS1				.FILL #1
NEG65				.FILL #-65
NEG26				.FILL #-26
POS65				.FILL #65
POS91				.FILL #91
NEG123				.FILL #-123
POS123				.FILL #123
POS97				.FILL #97
NEG64				.FILL #-64
POS90				.FILL #90
POS64				.FILL #64

INITS			.STRINGZ "Hello, welcome to my Caesar Cipher program!\n"
INITQ				.STRINGZ "Do you want to (E)ncryt or (D)ecrypt or e(X)it?\n"
CIPHER_Q			.STRINGZ "What is the cipher (1-25)?\n"
STRING_Q			.STRINGZ "What is the string you want decoded or encoded (up to 200 chars)?\n"
ENCRYPTIONM			.STRINGZ "<Encrypted>"
DECRYPTIONM			.STRINGZ "<Decrypted>"
SPACE				.STRINGZ "\n"
BYE				.STRINGZ "Bye, thanks for playing.\n"

ARRAY				.BLKW #100
R0_ORIG				.BLKW #1
R1_ORIG				.BLKW #1
R2_ORIG				.BLKW #1
R3_ORIG				.BLKW #1
R4_ORIG				.BLKW #1

CRYPTIONSIGN 			.BLKW #1
CIPHER				.BLKW #1
CHARCOUNT			.BLKW #1


.END

:code:
Is there any fix to my problems?!

This post has been edited by modi123_1: 21 May 2017 - 08:37 PM
Reason for edit:: In the future, please use the [code] tag button in the editor..


Is This A Good Question/Topic? 0
  • +

Replies To: I am creating two arrays, one with a encoded message and one decoded

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2130
  • View blog
  • Posts: 4,196
  • Joined: 30-May 10

Re: I am creating two arrays, one with a encoded message and one decoded

Posted 21 May 2017 - 11:27 PM

> I'm getting 'label' cannot be represented in 9-bit offset in the second assembler's check
It means you have too many instructions between your 'branch' or 'jump' instruction and the place where you want to go to.

If A calls B and C, but C is out of reach, you can sometimes arrange the code as

B
A
C

where both B and C are reachable from A.

Instead of
A
B
C

where C is out of reach from A.

> AND R0, R0, #0
You seem to be clearing registers an awful lot - more than might be necessary.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1