Question: . orig x 3 0 0 0 ;; You do not need to write anything here LD R 6 , STACK _ PTR ;; Pushes

.orig x3000
;; You do not need to write anything here
LD R6, STACK_PTR
;; Pushes arguments (address of node 1, target node 5)
ADD R6, R6,-1
AND R1, R1,0
ADD R1, R1,5
STR R1, R6,0
ADD R6, R6,-1
LD R1, STARTING_NODE_ADDRESS
STR R1, R6,0
JSR DFS
LDR R0, R6,0
ADD R6, R6,3
HALT
STACK_PTR .fill xF000
STARTING_NODE_ADDRESS .fill x6110
VISITED_VECTOR_ADDR .fill x4199 ;; stores the address of the visited vector.
;; SET_VISITED Pseudocode
;; Parameter: The address of the node
;; Updates the visited vector to mark the given node as visited
;; SET_VISITED(addr node){
;; visited = mem[mem[VISITED_VECTOR_ADDR]];
;; data = mem[node];
;; mask =1;
;; while (data >0){
;; mask = mask + mask;
;; data--;
;; }
;; mem[mem[VISITED_VECTOR_ADDR]]=(visited | mask); //Hint: Use DeMorgan's Law!
;; }
SET_VISITED ;; Do not change this label! Treat this as like the name of the function in a function header
;; Code your implementation for the SET_VISITED subroutine here!
RET
;; IS_VISITED Pseudocode
;; Parameter: The address of the node
;; Returns: 1 if the node has been visited, 0 if it has not been visited
;; IS_VISITED(addr node){
;; visited = mem[mem[VISITED_VECTOR_ADDR]];
;; data = mem[node];
;; mask =1;
;; while (data >0){
;; mask = mask + mask;
;; data--;
;; }
;; return (visited & mask)!=0;
;; }
IS_VISITED ;; Do not change this label! Treat this as like the name of the function in a function header
;; Code your implementation for the IS_VISITED subroutine here!
RET
;; DFS Pseudocode (see PDF for explanation and examples)
;; Parameters: The address of the starting (or current) node, the data of the target node
;; Returns: the address of the node (if the node is found),0 if the node is not found
;; DFS(addr node, int target){
;; SET_VISITED(node);
;; if (mem[node]== target){
;; return node;
;; }
;; result =0;
;; for (i = node +1; mem[i]!=0 && result ==0; i++){
;; if (! IS_VISITED(mem[i])){
;; result = DFS(mem[i], target);
;; }
;; }
;; return result;
;; }
DFS ;; Do not change this label! Treat this as like the name of the function in a function header
;; Code your implementation for the DFS subroutine here!
RET
.end
;; Assuming the graphs starting node (1) is at address x6100, here's how the graph (see below and in the PDF) is represented in memory
;;
;; 03
;; \/|\
;; 41-2
;; \/|
;; 5-6
;;
.orig x4199
.fill 0 ;; visited set will be at address x4199, initialized to 0
.end
.orig x6110 ;; node 1 itself lives here at x6110
.fill 1 ;; node.data (1)
.fill x6120 ;; node 2 lives at this address
.fill x6130 ;; node 3 lives at this address
.fill x6150 ;; node 5 lives at this address
.fill 0
.end
.orig x6120 ;; node 2 itself lives here at x6120
.fill 2 ;; node.data (2)
.fill x6110 ;; node 1 lives at this address
.fill x6130 ;; node 3 lives at this address
.fill x6160 ;; node 6 lives at this address
.fill 0
.end
.orig x6130 ;; node 3 itself lives here at x6130
.fill 3 ;; node.data (3)
.fill x6110 ;; node 1 lives at this address
.fill x6120 ;; node 2 lives at this address
.fill x6140 ;; node 4 lives at this address
.fill 0
.end
.orig x6140 ;; node 4 itself lives here at x6140
.fill 4 ;; node.data (4)
.fill x6100 ;; node 0 lives at this address
.fill x6130 ;; node 3 lives at this address
.fill x6150 ;; node 5 lives at this address
.fill 0
.end
.orig x6100 ;; node 0 itself lives here at x6000
.fill 0 ;; node.data (0)
.fill x6140 ;; node 4 lives at this address
.fill 0
.end
.orig x6150 ;; node 5 itself lives here at x6150
.fill 5 ;; node.data (5)
.fill x6110 ;; node 1 lives at this address
.fill x6140 ;; node 4 lives at this address
.fill x6160 ;; node 6 lives at this address
.fill 0
.end
.orig x6160 ;; node 6 itself lives here at x6160
.fill 6 ;; node.data (6)
.fill x6120 ;; node 2 lives at this address
.fill x6150 ;; node 5 lives at this address
.fill 0
.end
How would I implement this in LC-3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!