加入 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 中平常會看到的樣子。他們也會幫助你發現那些 你不知道自己不知道的事。
進一步了解引導