![](/img/trans.png)
[英]How do I store more than one user entered integer without using an array in MIPS?
[英]Assembly MIPS - How do I store an integer from the user into memory?
所以,我不知道裝配是如何工作的,也不知道我在做什么。 我以為我做了,但當然我錯了。 所以這是我的問題 - 我甚至不知道如何讓用戶輸入一個整數,所以我可以將它存儲在內存中。 我也不知道我的變量是否對齊,因為我甚至不理解“對齊”究竟是什么。 下面是我的匯編代碼,以及顯示我想要代碼執行的內容的注釋。 請幫忙
.data
# variables here
intPrompt: .asciiz "\nPlease enter an integer.\n"
stringPrompt: .asciiz "\nPlease enter a string that is less than 36 (35 or less) characters long.\n"
charPrompt: .asciiz "\nPlease enter a single character.\n"
int: .space 4
string: .space 36
char: .byte 1
.text
.globl main
main:
# print the first prompt
li $v0, 4
la $a0, intPrompt
syscall
# allow user to enter an integer
li $v0, 5
syscall
# store the input in `int`
# don't really know what to do right here, I want to save the user inputed integer into 'int' variable
sw $v0, int
syscall
您應該將“int”變量的類型從.space更改為.word
最后它應該是這樣的:
.data
# variables here
intPrompt: .asciiz "\nPlease enter an integer.\n"
stringPrompt: .asciiz "\nPlease enter a string that is less than 36 (35 or less) characters long.\n"
charPrompt: .asciiz "\nPlease enter a single character.\n"
int: .word
string: .space 36
char: .byte 1
main:
li $v0, 4 #you say to program, that you're going to output string which will be in the $a0 register
la $a0, intPrompt #here you load your string from intPromt var. to $a0
syscall #this command just executes everything that you have written before >> it prints string, which is in $a0
li $v0, 5 #this command says: "Hey, read an integer from console and put it in $v0!"
syscall #this command executes all previous commands ( li $v0, 5 )
sw $v0, int #sw -> store word, here you move value from $v0 to "int" variable
syscall #executes (sw $v0, int), here you have your input number in "int" variable
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.