加入 Exercism 的 MIPS Assembly 轨道,即可获得 70 个练习 还会自动分析 你的代码,并提供 个性化指导, 而且全部100% 免费。
# Convert ascii string of binary digits to integer
#
# $a0 - input, pointer to null-terminated string of 1's and 0's
# $v0 - output, integer form of binary string
# $t0 - ascii value of the char pointed to
# $t1 - integer value (0 or 1) of the char pointed to
.globl binary_convert
binary_convert:
li $v0, 0 # Reset accumulator to 0.
loop:
lb $t0, 0($a0) # Load a character,
beq $t0, $zero, end # if it is null then return.
sll $v0, $v0, 1 # Otherwise shift accumulator left,
addi $t1, $t0, -48 # calculate the value of the character,
or $v0, $v0, $t1 # and add that to the accumulator.
addi $a0, $a0, 1 # Finally, increment the pointer
j loop # and loop.
end:
jr $ra
借助有趣又有收获的编程练习提升编程水平,在 Exercism 上检验你对概念的理解。
查看 Exercism 上所有 MIPS Assembly 练习
MIPS 是一门简单的汇编语言,常用于大学的计算机体系结构课程。
MIPS 是数十亿已出货产品的核心。
MIPS 有大量文档,尤其是在计算机体系结构的学术教材中。
凭借紧凑的指令实现快速的执行速度,这一直是它自诞生以来的重要特点。
作为基于 RISC 的汇编语言,它拥有小巧且正交的指令集。
MIPS 于 1985 年首次问世,为应对新的挑战不断演进,并自 2014 年起保持稳定。
每种语言都有自己的做事方式,MIPS Assembly 也不例外。我们的导师会帮助你学会像 MIPS Assembly 开发者那样思考,并教你如何写出地道的 MIPS Assembly 代码。解完一道练习后,把它提交给我们由志愿者组成的团队,他们会给你提示、想法和反馈,帮你写出更接近 MIPS Assembly 中常见风格的代码,还会帮你发现那些你并不知道自己不知道的东西。
了解更多关于指导的内容