print_list:
# Function to traverse the linked list and print the values
# Inputs: a1 = head of the linked list
#.include "lab4_testbench.asm"
#using temp. register, loop thru list until u reach end. address pointer = NULL
#print each value, move to next value
mv t0, a1 #moving head of linked list to register t0 ADDRESS
#could this be the reason?
loop:
beqz t0, arnold #if next address leads to NULL, stop printing. end of list reached.
lw a0, 0(t0) #a0 has KEY. accessed from address stored in t0
print_int(a0) #print the element
print_str(comma_space)
lw t0, 4(t0) #t0 ADDRESS updating to next ADDRESS in linked list
#beqz t0, loopinthesoup #if next address leads to NULL, stop printing. end of list reached.
j loop #repeat until null is reached.
arnold:
print_str(endoflistmsg)
print_str(newline)
ret
I’m having an issue printing values from a list that feeds into a function print_list. For whatever reason, it only prints one element from a list, the greatest one, which is a separate issue in a different file.
I’m not sure if I’m pointing to incorrect addresses, or if I’m not retrieving them correctly. I have a hunch that says there’s something wrong with the loop itself, but I’m not sure
New contributor
Julian Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.