简体   繁体   English

使用 MIPS 32 汇编语言,如何使用 addu 和 ori 命令加载和添加 4 个整数?

[英]Using MIPS 32 assembly language, how can I use the addu and ori commands to load and add 4 integers?

This is what I have, however it doesn't want to do the last addu, which attempts to add together registers 10 and 13 into register 14. The last addu command puts the the letter 'e' into register 14.这就是我所拥有的,但是它不想执行最后一个 addu,它试图将寄存器 10 和 13 一起添加到寄存器 14。最后一个 addu 命令将字母“e”放入寄存器 14。

        .text
        .globl  main

main:
        ori     $8,$0,0x2       # put two's comp. two into register 8
        ori     $9,$0,0x3       # put two's comp. three into register 9
        ori     $11,$0,0x4      # put two's comp. four into register 11
        ori     $12,$0,0x5      # put two's comp. five into register 12
        addu    $10,$8,$9       # add register 8 and 9, put result in 10
        addu    $13,$11,$12     # add register 11 and 12, put result in 13
        addu    $14,$10,$13     # add register 10 and 13, put result in 14

## End of file

It's hex E, aka 0xe, aka 14(dec), not the letter 'e'.它是十六进制 E,又名 0xe,又名 14(dec),而不是字母“e”。

You're looking at the debugger showing you content in hex.您正在查看以十六进制显示内容的调试器。 This is not "output" but it is an interpretation of the values in the registers, done by the debugger.这不是“输出”,而是由调试器完成的对寄存器中值的解释。 The debugger has modes to show the registers in binary, hex, or decimal — use the QtSpim menu item "Registers".调试器具有以二进制、十六进制或十进制显示寄存器的模式——使用 QtSpim 菜单项“寄存器”。 The bugger doesn't really know what you want to show but it can switch all registers displayed from binary to hex to decimal.窃听器并不真正知道您要显示什么,但它可以将所有显示的寄存器从二进制切换到十六进制再到十进制。

The actual values held in the register are the same regardless of the chosen display form by the debugger.无论调试器选择何种显示形式,寄存器中保存的实际值都是相同的。 While the hardware uses binary to store the register values, the value stored in the register is just a number, no matter how we display it — and to be clear any character sequence for a number (like 100) is a display format using a number base.虽然硬件使用二进制来存储寄存器值,但存储在寄存器中的值只是一个数字,无论我们如何显示它 - 并且要清楚数字(如 100)的任何字符序列是使用数字的显示格式根据。 The registers do not know about display format and number bases, they just store numbers using binary — that's the debugger interpreting the number in a number base for display.寄存器不知道显示格式和数字基数,它们只是使用二进制存储数字 - 这是调试器在数字基数中解释数字以进行显示。 That they use binary only means that they cannot store numbers larger than 32 bits, but otherwise storing 100 decimal or hex 64 is all the same number in the register (same exact bit pattern).他们只使用二进制意味着他们不能存储大于 32 位的数字,但否则存储 100 个十进制或十六进制 64 在寄存器中都是相同的数字(完全相同的位模式)。

If you want actual output you need an instruction sequence to print numbers as character sequences, using a syscall of some sort — load a value to display into $a0 and use syscall #1 to print in decimal.如果你想要实际的 output 你需要一个指令序列来将数字打印为字符序列,使用某种系统调用 - 加载一个值以显示到$a0并使用系统调用 #1 以十进制打印。 I don't know a print hex in QtSpim, but MARS (its cousin in MIPS simulation territory) has syscall #34 to print hex.我不知道 QtSpim 中的打印十六进制,但 MARS(它在 MIPS 模拟领域的表亲)具有系统调用 #34 来打印十六进制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM