gpt4 book ai didi

assembly - 如何在 MIPS 汇编语言中定义常量?

转载 作者:行者123 更新时间:2023-12-02 21:37:46 25 4
gpt4 key购买 nike

我在网上查了一下,但我唯一能找到的是这个语法PI = 3.1415,但由于某种莫名其妙的原因,这在我正在使用的MIPS模拟器程序中不起作用MARS 4.5 。我认为如果它是 MIPS 语言规范的一部分,它应该可以工作。当尝试汇编一个简单的 hello world 程序时,编译器说我的代码中存在无效的语言元素。这是代码本身:

################################################################################
# #
# This is a hello world program in the MIPS assembly language. It prints out #
# "Hello, World!" on the screen and exits. #
# #
################################################################################

# System call code constants
SYS_PRINT_STRING = 4
SYS_EXIT = 10

.data
msg: .asciiz "Hello, World!\n"

.text
.globl __start
__start:
la $a0, msg # Load the address of the string "msg" into the
# $a0 register
li $v0, SYS_PRINT_STRING # Store the system call for printing a string on
# the screen in the $v0 register
syscall

li $v0, SYS_EXIT # Store the system call to exit the program in the
# $v0 register
syscall

最佳答案

你想要的是一个替换宏。 MIPS 是一个指令集,除了指令本身之外它没有定义太多。指令集通常没有像高级语言那样的命名常量的概念。替换宏是由汇编器实现的,因此您需要检查汇编器文档。

对于 MARS,指令是 .eqv。示例:

.eqv SYS_PRINT_STRING 4

li $v0, SYS_PRINT_STRING

关于assembly - 如何在 MIPS 汇编语言中定义常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37880513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com