10 Replies - 5160 Views - Last Post: 21 May 2017 - 06:18 PM

#1 Jaybans  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-December 13

Need help with programming an address book in LC-3 Code

Posted 06 December 2013 - 04:59 AM

The assignment is to write a very simple address book program using the LC‐3 assembly language.  
Each person record has two fixed‐sized data fields: a name and a phone number, both of size 8 characters. Allocate enough memory to store 10 person records. 

The program has two database operations: 1) Add a new record; 2) Find a person record;  

Details of the operations: 
1)  Add a new record. 
Your program will prompt the user to enter a name and a phone number and then save that into the 
appropriate allocated memory space. 

2) Find a person record. 
Your program will prompt the user to enter a name. It will then search the database for a matching 
name. Print out the person’s phone number if found, else print out a message saying not found. 

	.ORIG X3000	;INITIALIZE PROGRAM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;REGISTER DATA

	;REGISTER 0 IS USED FOR INPUTTING INFORMATION BY THE USER
	;REGISTER 1 IS USED AS THE MENU TESTER (CAN BE USED, ALWAYS INITIALIZED)
	;REGISTER 2 IS COUNTER WITH R5 (CAN BE USED, ALWAYS REINITIALIZED)
	;REGISTER 3 IS ASCII CONVERTER (CAN BE USED, ALWAYS REINITIALIZED)
	;REGISTER 4 IS USED TO STORE MEMORY LOCATION OF BOOK (DO NOT USE)
	;REGISTER 5 IS USED TO COUNT HOW MANY FILES HAVE BEEN STORED (DO NOT USE)
	;REGISTER 6 IS USED AS A COUNTER IN STORING AND FINDING INFORMATION (DO NOT USE)
	;REGISTER 7 IS UNUSED
	;DO NOT USE R4, R5, R6, R7

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;START OF MAIN CODE

MAIN
	AND R5, R5, #0	;INITIALIZES REGISTER
	LEA R0, BOOK
	ST R0, CURRENT
MENU			;MENU FUNCTION
	LEA R0, PROMPT	;PROMPT THEM TO ADD OR FIND
	IN
	LD R3, NTHIRTY	;LOADS NEGATIVE THIRTY INTO R3
	ADD R0,R0,R3	;CONVERTS R0 INTO DECIMAL FROM ASCII 
	BRnz SKIP	;CONTINUE IF NOT A 0 OR NEGATIVE NUMBER

FNDLOOP	LD R1, TWO	;LOAD R2 WITH 2
	ADD R1, R1, #-4	;MAKES 2 INTO -2
	ADD R1, R0, R1	;TESTS TO SEE IF USER INPUT WAS A 1 TO FIND AN ADDRESS
	BRn ADDLOOP	;LEAVE FIND LOOP
	BRz FIND	;CALLS THE FIND FUNCTION
	BRp MENU	;INVALID NUMBER, GOT BACK TO MENU

ADDLOOP	LD R1, ONE	;LOAD R1 WITH 1
	ADD R1, R1, #-2	;MAKES 1 INTO -1
	ADD R1, R0, R1	;TESTS TO SEE IF USER INPUT WAS A 1 TO ADD AN ADDRESS
	BRnp SKIP	;LEAVE ADD LOOP TO A HALT
	BRz ADDRESS	;CALLS THE ADD FUNCTION
	
HOWFULL	AND R2, R2, #0	;INITIALIZES R2
	ADD R2, R2, #-9	;MAKES R2 -10
	ADD R5, R5, #1	;INCREMENTS R5 BY 1
	ADD R2, R2, R5	;ADDS R2 AND R5 TOGETHER, IF R5 BECOMES 10 IT WILL EQUAL 0
	BRz BKFULL	;IF R2 IS ZERO, ADDRESS BOOK IS FULL
	BRnzp MENU	;BACK TO THE BEGINNING

SKIP	
	LEA R0, GBYE	;PROMPTS A GOODBYE MESSAGE
	HALT		;CALL PROGRAM TO A HALT

BKFULL
	LEA R0, FULLBK	;PROMPTS A FULL BOOK MESSAGE
	IN
	LD R1, TWO	;LOAD R2 WITH 2
	ADD R1, R1, #-4	;MAKES 2 INTO -2
	ADD R1, R0, R1	;TESTS TO SEE IF USER INPUT WAS A 1 TO FIND AN ADDRESS
	BRz FIND	;IF 0 CONTINUES TO FIND FUNCTION
	HALT		;CALL PROGRAM TO A HALT
	
ADDRESS
	LD R6, EIGHT	;INITIALIZES R6 TO BE 8 SO IT CAN LOOP 8 TIMES
	LEA R0, PROMPT2	;PROMPTS QUESTION TO ENTER A NAME
LOOP1	IN		;GET CHARACTER OF NAME
	LD R4, CURRENT	;LOAD ADDRESS OF NAME LOCATION
	ADD R4, R4, #1	;STORE RECORD INTO THE PLACE
	ST R4, CURRENT
	STR R0, R4, #0
	ADD R6, R6, #-1	;DECREASES COUNTER R6 BY 1
	BRp LOOP1	;IF IT IS STILL POSITIVE IT LOOPS TO COMPLETE THE NAME

	LD R6, EIGHT	;INITIALIZES R6 TO BE 8 SO IT CAN LOOP 8 TIMES
	LEA R0, PROMPT3	;PROMPTS QUESTION TO ENTER A PHONE NUMBER
LOOP2	IN		;GET CHARACTER OF RECORD
	LD R4, CURRENT	;LOAD ADDRESS OF NAME LOCATION
	ADD R4, R4, #1	;STORE RECORD INTO THE PLACE
	ST R4, CURRENT
	STR R0, R4, #0
	ADD R6, R6, #-1	;DECREASES COUNTER R6 BY 1
	BRp LOOP2	;IF IT IS STILL POSITIVE IT LOOPS TO COMPLETE THE PHONE NUMBER
	LEA R0, THANKYOU
	BRNZP MENU	;BACK TO MENU 

FIND
	LEA R0, PROMPT4
	IN
	
	LEA R0, PROMPT5
	IN

	BRNZP MENU	;BACK TO MENU

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;START OF .FILL DATA

NTHIRTY	.FILL x-30
TEN	.FILL #10
ONE	.FILL #1
TWO	.FILL #2
EIGHT	.FILL #8

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;START OF STRING PROMPTS

FULLBK
	.STRINGZ "Address book is full. Would you like to find a record?"

THANKYOU
	.STRINGZ "Thank you!"

GBYE
	.STRINGZ "Goodbye!"

PROMPT	
	.STRINGZ "Enter 1 to add a new record and 2 to find a record and 0 to exit:" 

PROMPT2
	.STRINGZ "Enter in an 8 character or less name:"

PROMPT3
	.STRINGZ "Enter in an 8 character or less number:"

PROMPT4
	.STRINGZ "Enter in an 8 character or less name:"

PROMPT5
	.STRINGZ "Enter in an 8 character or less number:"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;START OF ADDRESS BOOK DATA

CURRENT	.BLKW #1
BOOK	.BLKW #160

	.END		;END PROGRAM




I currently get the errors
Line 21: Instruction references label 'BOOK' that cannot be represented in a 9-bit signed PC offset
Line 22: Instruction references label 'CURRENT' that cannot be represented in a 9-bit signed PC offset
Line 67: Instruction references label 'CURRENT' that cannot be represented in a 9-bit signed PC offset
Line 69: Instruction references label 'CURRENT' that cannot be represented in a 9-bit signed PC offset
Line 77: Instruction references label 'CURRENT' that cannot be represented in a 9-bit signed PC offset
Line 79: Instruction references label 'CURRENT' that cannot be represented in a 9-bit signed PC offset
Line 90: Instruction references label 'PROMPT5' that cannot be represented in a 9-bit signed PC offset

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with programming an address book in LC-3 Code

#2 turboscrew  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 152
  • View blog
  • Posts: 1,032
  • Joined: 03-April 12

Re: Need help with programming an address book in LC-3 Code

Posted 06 December 2013 - 01:23 PM

LEA is PC-relative. The offset can be at most 256.
instead of "LEA R0, BOOK"
do "LD R0 BOOK"
To access the data, use
"LDI R1, R0
Was This Post Helpful? 0
  • +
  • -

#3 turboscrew  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 152
  • View blog
  • Posts: 1,032
  • Joined: 03-April 12

Re: Need help with programming an address book in LC-3 Code

Posted 07 December 2015 - 12:09 PM

I could sent you a proposition how to handle the situation with avoiding too much editing. Do you have an e-mail address?
Was This Post Helpful? 0
  • +
  • -

#4 buffer0ver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-December 15

Re: Need help with programming an address book in LC-3 Code

Posted 07 December 2015 - 12:13 PM

View Postturboscrew, on 07 December 2015 - 12:09 PM, said:

I could sent you a proposition how to handle the situation with avoiding too much editing. Do you have an e-mail address?


Thanks and yes you can send it to <mod: email removed>. Thanks mate!

This post has been edited by modi123_1: 07 December 2015 - 12:47 PM

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13484
  • View blog
  • Posts: 53,826
  • Joined: 12-June 08

Re: Need help with programming an address book in LC-3 Code

Posted 07 December 2015 - 12:26 PM

Ah, why are we all responding to something back in 2013?
Was This Post Helpful? 0
  • +
  • -

#6 buffer0ver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-December 15

Re: Need help with programming an address book in LC-3 Code

Posted 07 December 2015 - 12:29 PM

View Postmodi123_1, on 07 December 2015 - 12:26 PM, said:

Ah, why are we all responding to something back in 2013?


I want to get the user's code to run and asked for help so I can understand it. Trying to learn assembly using LC3 simulator.
Was This Post Helpful? 0
  • +
  • -

#7 turboscrew  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 152
  • View blog
  • Posts: 1,032
  • Joined: 03-April 12

Re: Need help with programming an address book in LC-3 Code

Posted 07 December 2015 - 12:31 PM

Gave an example how to handle one such label.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13484
  • View blog
  • Posts: 53,826
  • Joined: 12-June 08

Re: Need help with programming an address book in LC-3 Code

Posted 07 December 2015 - 12:34 PM

I would prefer the help stay on the forum to benefit everyone. Additionally - if this is a new question I should split this up and you can post what you have tried.
Was This Post Helpful? 0
  • +
  • -

#9 turboscrew  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 152
  • View blog
  • Posts: 1,032
  • Joined: 03-April 12

Re: Need help with programming an address book in LC-3 Code

Posted 07 December 2015 - 12:38 PM

Quote

I would prefer the help stay on the forum

I agree.
Was This Post Helpful? 0
  • +
  • -

#10 BananaSlug12321  Icon User is offline

  • New D.I.C Head

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

Re: Need help with programming an address book in LC-3 Code

Posted 21 May 2017 - 05:40 PM

View Postturboscrew, on 07 December 2015 - 12:09 PM, said:

I could sent you a proposition how to handle the situation with avoiding too much editing. Do you have an e-mail address?

Hello turboscrew, I hope you're still active. I am doing a very similar program with two arrays, and am getting the same offset errors on the asm's second check. Do you think you could possibly send me what you sent the other guy for help?
Was This Post Helpful? 0
  • +
  • -

#11 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5887
  • View blog
  • Posts: 20,094
  • Joined: 05-May 12

Re: Need help with programming an address book in LC-3 Code

Posted 21 May 2017 - 06:18 PM

BananaSlug12321: Please open to own thread instead of reviving an old thread.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1