Question: . orig x 3 0 0 0 ;; You do not need to write anything here LD R 6 , STACK _ PTR ;; Pushes
orig x
;; You do not need to write anything here
LD R STACKPTR
;; Pushes arguments address of node target node
ADD R R
AND R R
ADD R R
STR R R
ADD R R
LD R STARTINGNODEADDRESS
STR R R
JSR DFS
LDR R R
ADD R R
HALT
STACKPTR fill xF
STARTINGNODEADDRESS fill x
VISITEDVECTORADDR fill x ;; stores the address of the visited vector.
;; SETVISITED Pseudocode
;; Parameter: The address of the node
;; Updates the visited vector to mark the given node as visited
;; SETVISITEDaddr node
;; visited memmemVISITEDVECTORADDR;
;; data memnode;
;; mask ;
;; while data
;; mask mask mask;
;; data;
;;
;; memmemVISITEDVECTORADDRvisited mask; Hint: Use DeMorgan's Law!
;;
SETVISITED ;; Do not change this label! Treat this as like the name of the function in a function header
;; Code your implementation for the SETVISITED subroutine here!
RET
;; ISVISITED Pseudocode
;; Parameter: The address of the node
;; Returns: if the node has been visited, if it has not been visited
;; ISVISITEDaddr node
;; visited memmemVISITEDVECTORADDR;
;; data memnode;
;; mask ;
;; while data
;; mask mask mask;
;; data;
;;
;; return visited & mask;
;;
ISVISITED ;; Do not change this label! Treat this as like the name of the function in a function header
;; Code your implementation for the ISVISITED 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 if the node is not found
;; DFSaddr node, int target
;; SETVISITEDnode;
;; if memnode target
;; return node;
;;
;; result ;
;; for i node ; memi && result ; i
;; if ISVISITEDmemi
;; result DFSmemi 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 is at address x here's how the graph see below and in the PDF is represented in memory
;;
;;
;;
;;
;;
;;
;;
orig x
fill ;; visited set will be at address x initialized to
end
orig x ;; node itself lives here at x
fill ;; node.data
fill x ;; node lives at this address
fill x ;; node lives at this address
fill x ;; node lives at this address
fill
end
orig x ;; node itself lives here at x
fill ;; node.data
fill x ;; node lives at this address
fill x ;; node lives at this address
fill x ;; node lives at this address
fill
end
orig x ;; node itself lives here at x
fill ;; node.data
fill x ;; node lives at this address
fill x ;; node lives at this address
fill x ;; node lives at this address
fill
end
orig x ;; node itself lives here at x
fill ;; node.data
fill x ;; node lives at this address
fill x ;; node lives at this address
fill x ;; node lives at this address
fill
end
orig x ;; node itself lives here at x
fill ;; node.data
fill x ;; node lives at this address
fill
end
orig x ;; node itself lives here at x
fill ;; node.data
fill x ;; node lives at this address
fill x ;; node lives at this address
fill x ;; node lives at this address
fill
end
orig x ;; node itself lives here at x
fill ;; node.data
fill x ;; node lives at this address
fill x ;; node lives at this address
fill
end
How would I implement this in LC
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
