簡體   English   中英

有人可以向我解釋此MIPS代碼的某些部分嗎?

[英]Can someone explain some parts of this MIPS code to me?

 1 .data
 2 msg1: .word 0:24
 3 .text
 4 .globl main
 5 main:
 6 li $v0, 8 #syscall for read str
 7 la $a0, msg1 #load address of msg1 to store string
 8 li $a1, 100 #msg1 is 100 bytes
 9 syscall
10 lb $t0, 5($a0) #load the character into $t0
11 li $t1, 'a' #get value of 'a'
12 blt $t0, $t1, nomodify #do nothing if letter is less than 'a'
13 li $t1, 'z' #get value of 'z'
14 bgt $t0, $t1, nomodify #do nothing if letter is greater than 'z'
15 addi $t0, $t0, -0x20 #encap the letter
16 sb $t0, 5($a0) #store the new letter
17 nomodify:
18 li $v0, 4 #syscall for print str
19 syscall
20 li $v0, 10 #system call for exit
21 syscall # we are out of here.

首先,此代碼的目的是從用戶那里獲得一個字符串並打印回該字符串。

我的第一個問題:

在第10行中,為什么專門從$ a0 + 5加載一個字節? 我知道$ a0是要打印的輸入字符串,但是我不明白為什么它要偏移5。

第二個問題:

在第11至14行中,如果字符小於'a'或字符大於'z',為什么要分支到nomodify? 這不是說如果不在az范圍內時打印字符嗎?

第三個問題:

在第11-16行中,如果字符不小於'a'也不大於'z',則第15行說在$ t0中添加立即值-0x20,注釋說這是為了“對字母加大括號”。 這意味着什么?

最后:

繼續使用“ char”一詞使我感到困惑。 這段代碼是讀取/打印一個字符串吧? 字符不只是字符串的一個字符嗎?

1 .data 2 msg1: .word 0:24 3 .text 4 .globl main 5 main: 6 li $v0, 8 #syscall for read str 7 la $a0, msg1 #load address of msg1 to store string 8 li $a1, 100 #msg1 is 100 bytes 9 syscall 18 li $v0, 4 #syscall for print str 19 syscall 20 li $v0, 10 #system call for exit 21 syscall # we are out of here.

這將是僅讀取/寫入輸入字符串的真實代碼。 我問的問題代碼(特別是第10-17行)對第六個字符做了額外的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM