【发布时间】:2013-11-30 19:44:45
【问题描述】:
我正在尝试在 MIPS 中实现 puts。我有一个程序putchar 在屏幕上打印一个字符:
.text
putchar:
lui $t0, 0xffff # base address of memory map
XReady:
lw $t1, 8($t0) #read from transmitter control register
andi $t1, $t1, 0x1 # extract ready bit
beqz $t1, XReady # if 1, store char ; else, loop
sw $a0, 12($t0) # send character to display
jr $ra # return to place in program before function call
在我的主子程序中,我将 $a0 设置为我要打印的字符串,然后我调用 puts :
la $a0, array # defined in .data as -- array: .space 2000 --
gal puts
在puts 的第 242 行(标有 *)上,我收到一个错误提取地址未与字边界对齐
.text
puts:
addi $sp, $sp, -24 # make room for 6 registers
sw $ra, 20($sp) # save $ra on the stack
sw $s0, 16($sp) # save $s0 on the stack
sw, $s1, 12($sp) # save $s1 on the stack
sw, $s2, 8($sp) # save $s2 on the stack
sw, $s3, 4($sp) # save $s3 on the stack
sw, $s4, 0($sp) # save $s4 on the stack
move $s0, $a0 # copy parameter $a0 into $s0
move $s1, $a1 # copy parameter $a0 into $s1
move $s2, $a2 # copy parameter $a0 into $s2
move $s3, $a3 # copy parameter $a0 into $s3
move $s4, $zero # s4 is a character counter. $s4 = 0
getsLoop:
addi $t0, $zero, 0x00 # Put NULL ascii character inside $t0
sll $t1, $s4, 2 # create buffer storing address ($t1 = $s1 * 4)
add $t2, $s0, $t1 # register #t2 now holds buffer address
* lw $t3, ($s0) # load char into #t3
beq $t3, $t0, exitPuts # exit puts if the current character is the NULL character
move $a0, $t3 # put the character to print inside $a0, accessible by putchar
jal putchar # print char using putchar
addi $s0, $s0, 1 # character count += 1
j getsLoop # Loop to print next character
exitPuts:
lw $s4, 0($sp) # restore stack
lw $s3, 4($sp) # -
lw $s2, 8($sp) # -
lw $s1, 12($sp) # -
lw $s0, 16($sp) # -
lw $ra, 20($sp) # -
addi $sp, $sp, 20 # pop from stack
jr $ra # return
我不知道为什么会出现这个错误...$s0 不是在 main 中定义的array 的地址吗?
【问题讨论】:
标签: mips