我用 MIPS 汇编写了这个简单的程序:
.data
.text
main:
li $v0, 12 # read_char
syscall
move $a0, $v0
li $v0, 11 # print_char
syscall
j main # repeat forever
Run Code Online (Sandbox Code Playgroud)
当我在 QtSpim 中运行它时,它工作正常:它从控制台获取一个字符,并在输入后立即打印它,然后重复。但是,QtSpim 的控制台不允许我为我的程序粘贴输入(我可以这样做,但不会被读取)。所以我尝试在spim for Linux(命令行)版本 9.1.8 中运行它。它可以工作,但是当输入一个字符时它不会立即做出反应;它总是等待换行符,即使在没有剪切和粘贴的情况下输入字符也是如此。所以我希望这种行为:
(spim) load "echo.asm"
(spim) run
hheelllloo
Run Code Online (Sandbox Code Playgroud)
但我得到了这个:
(spim) load "echo.asm"
(spim) run
hello [I press Enter here]
hello
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?提前致谢。
我正在尝试编写一个简单的代码,将字符串和整数输入保存到一个数组中,然后将它们打印出来(稍后我还将添加另一个对它们进行排序的部分,但我必须先使其工作)。
.data
array: .space 40 #10 elements array
in_name:
.asciiz "\nInsert name: "
in_date:
.asciiz "\nInsert date (mmdd): "
appt:
.asciiz "\nList: "
spaz: .asciiz " "
.text
main:
la $s0, array #load array in s0
addi $t0, $zero, 0 #t0=0 counter
addi $s1, $zero, 0 #s1=0 array size counter
j Input
Input:
li $v0, 4
la $a0, in_date
syscall #ask date
li $v0, 5
syscall #read date
add $t1, $zero, $t0 #offset in t1
add $t1, $t1, $t1 #t1*2 …Run Code Online (Sandbox Code Playgroud) I am trying to convert binary to decimal in the MIPS language, using the MARS simulator. The program accepts a binary number, and then does the conversion, by multiplying (shift left by the number's place $t9). Another way of saying that is multiplying each 1 digit by 2 raised to the power of the place, and summing that result.
I do not have a very good understanding of how values are stored and communicated between ascii, decimal, and the problem …
我在两个 $t 寄存器中加载了一个浮点双精度数,现在我想将它除以 (-4)(不使用 fp 指令)并将其存储回 $f 寄存器。
mfc1 $t0, $f0 #$f0 = 0x00000000
mfc1 $t1, $f1 #$f1 = 0x40240000
div $t1, $t1, -4
mfhi $t0 #move the remainder to $t0
mflo $t1 #move the quotient to $t1
mtc1 $t0, $f0
mtc1 $t1, $f1
# store the $f0 result in memory
# print X/(-4)
mov.d $f12, $f0
li $v0, 3
syscall
Run Code Online (Sandbox Code Playgroud)
但这给出了非常意外的结果,即 -2.231744757682269E231
任何帮助将不胜感激。
我需要打印一个数组的单元格,我有一个包含“HELLO_WORLD”这个词的数组,我设法自己打印了一个索引,但我无法一一打印所有单元格,这是代码:
loop:
la $t0, hexdigits # address of the first element
lb $a0, 5($t0) # hexdigits[10] (which is 'A')
li $v0, 11 #system call service
syscall
addi $a0, $a0, 2
li $v0, 11 # I will assume syscall 11 is printchar (most simulators support it)
syscall # issue a system call
j end
Run Code Online (Sandbox Code Playgroud)
无论如何,是否可以将指令 lb $a0, $s0($t0) 与我可以随时递增的寄存器一起使用?而不仅仅是一个数字?
假设 $t2= 0x55555550,然后执行以下指令:
andi $t2, $t2, -1
Run Code Online (Sandbox Code Playgroud)
$t2 变成 0x0005550
MIPS 仿真器1证实了这一点
然而,这不是我所期望的。我认为答案应该是 0x55555550 & 0xFFFFFFFF = 0x55555550。我认为常量 -1 在和逻辑之前被符号扩展为 0xFFFFFFFF。但似乎答案是 0x55555550 & 0x0000FFFF
为什么 -1 被符号扩展为 0x0000FFFF 而不是 0xFFFFFFFF
脚注 1:编者注:启用“扩展伪指令”的 MARS 确实将其扩展为多条指令以0xffffffff在 tmp 寄存器中生成,因此保持$t2不变。否则 MARS 和 SPIM 都会以不可编码的错误拒绝它。其他汇编程序可能有所不同。
assembly mips sign-extension zero-extension immediate-operand
寄存器$t0包含值0x10008040。写出 MIPS 指令的机器代码,该指令从主存储器地址处加载一个字
0x10008048,并将结果存储在寄存器中$s1。该指令应使用 register $t0。作为机器代码的十六进制值回答。
我已经在这个问题上走了这么远
lw $t0, 8($s1)
Run Code Online (Sandbox Code Playgroud)
然后我堆栈如何做感谢您的帮助。
我一直在寻找这个问题的答案,但找不到明确的答案。它是在多个寄存器之间分配数字还是不能简单地处理它?我尝试用 MARS 测试它并使用数字 4294967296,即 0x100000000,但寄存器仅保存了 0x00000000,因此省略了“1”位。有没有办法处理这样的数字?
我正在考虑如何否定 mips32 中的有符号整数。我的直觉是使用 2 的补码的定义,例如:(假设$s0是要否定的数字)
nor $t0, $s0, $s0 ; 1's complement
addiu $t0, $t0, 1 ; 2's = 1's + 1
Run Code Online (Sandbox Code Playgroud)
然后我意识到可以这样做:
sub $t0, $zero, $s0
Run Code Online (Sandbox Code Playgroud)
所以……有什么区别?哪个更快?IIRC sub 会尝试检测溢出,但是这个 make 会更慢吗?最后,有没有其他方法可以做到这一点?
处理器型号 I
? Registers
? PC – Program Counter
? Single data register (accumulator) without name
? We will use symbol A to describe operations on this register
? Stack with an unspecified implementation
? Data specified by name or value
? More realistic model will follow later
Instruction Action Description
---------------------------------------------------------------------
load data A = data Load data to accumulator
store data data = A Store data from accumulator to memory
add data A += data Add data to …Run Code Online (Sandbox Code Playgroud)