我做错了什么/尝试运行 MIPS 程序来构建/绘制一个盒子
这是我写的MIPS程序。但我的程序不会构造/绘制一个盒子。
.data
button: .struct
xleft: .byte 0
ytop: .byte 0
size: .byte 0
state: .byte 0
label: .space 4
action: .word
.data
box: .struct
ulc: .byte
top: .byte
urc: .byte
left: .byte
right: .byte
llc: .byte
bottom: .lrc
.data
pressed: .byte 201,205,184,186,174,211,196,217 #ASCII codes for program
drawBox(box *a0,byte left,byte top, size a3);
.code
drawBox: addi $sp,$sp,-1
sw $a0,($sp)
sw $a1,4($sp)
addi $t0,$a3,0xf
srl $t9,$a3,4
move $$a0,$a1
move $a1,$a2
syscall $xy
lw $t7,($sp)
syscall $print_char
lbu $a0,box.top($t7)
move $t1,$t8
b 2f
1: syscall $print_char
addi $t1,$t1,-1
2: bnez $t1,1b
lbu $a0,box.urc($t7)
syscall $print_char
move $t1,$t9
b 2f
syscall $print_char
addi
99: addi $sp,$sp,8
jr $ra
Here is the MIPS program i've written. But my program won't construct/draw a box.
.data
button: .struct
xleft: .byte 0
ytop: .byte 0
size: .byte 0
state: .byte 0
label: .space 4
action: .word
.data
box: .struct
ulc: .byte
top: .byte
urc: .byte
left: .byte
right: .byte
llc: .byte
bottom: .lrc
.data
pressed: .byte 201,205,184,186,174,211,196,217 #ASCII codes for program
drawBox(box *a0,byte left,byte top, size a3);
.code
drawBox: addi $sp,$sp,-1
sw $a0,($sp)
sw $a1,4($sp)
addi $t0,$a3,0xf
srl $t9,$a3,4
move $a0,$a1
move $a1,$a2
syscall $xy
lw $t7,($sp)
syscall $print_char
lbu $a0,box.top($t7)
move $t1,$t8
b 2f
1: syscall $print_char
addi $t1,$t1,-1
2: bnez $t1,1b
lbu $a0,box.urc($t7)
syscall $print_char
move $t1,$t9
b 2f
syscall $print_char
addi
99: addi $sp,$sp,8
jr $ra
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个程序充满了错误——语法错误等等。
bottom:
后面的.lrc
看起来像是下一行中的变量名称,在编辑过程中意外上移。drawBox(box *a0,...)
也不是有效的 MIPS 汇编语法 - 看起来它本来是一条注释,但您忘记了#
。堆栈帧设置代码 (addi $sp,$sp,-1
) 未对齐堆栈指针,并将导致存储失败(有趣的是,标签99:< 之后的堆栈帧恢复代码/code> 看起来不错)。还有其他错误。
整个程序看起来像是复制和复制的。从几个不同的来源粘贴在一起,完全不了解 MIPS 汇编语言,这个问题听起来像是一个家庭作业。首先尝试一个更简单的程序(将几个整数加在一起,然后编写一个简单的循环,然后编写一个函数来打印以零结尾的字符串,类似的东西) - 很明显,您已经超出了您的深度现在这个问题。
This program is full of errors - syntax errors and otherwise. The
.lrc
followingbottom:
looks like it's a variable name from the following line that got accidentally moved up during editing. ThedrawBox(box *a0,...)
isn't valid MIPS assembly syntax either - looks like it was intended to be a comment, but you forgot the#
. The stack frame setup code (addi $sp,$sp,-1
) misaligns the stack pointer and will cause the stores to fail (interestingly, the stack frame restore code following label99:
looks OK). There's other errors as well.The whole program looks like it was copy & pasted together from several different sources with absolutely no understanding of MIPS assembly language, and the problem sounds like a homework assignment. Try your hands at a simpler program first (add a couple integers together, then write a simple loop, then write a function to print a zero-terminated string, something like that) - it's fairly obvious that you're out of your depth with this problem right now.