/ *如何在hello后显示输入的名称? * /
.text
.globl main
main:
la $a0, prompt # load address of prompt into a0
li $v0, 4 # load instruction number to display string into v0
syscall # system call to print the prompt call
li $a1, 81 # set string length
la $a0, name # get address of string variable
li $v0, 8 # service call number for reading string from keyboard
syscall # Read string
la $a0, greeting # Display the greeting message
li $v0, 4 # load address of greeting into a0
syscall # call to system to print greeting call
la $a0, endl # load new line into a0
li $v0, 4 # load call code number to display the string into v0
syscall # call to system to print new line
li $v0, 10 # End of greeting program
syscall # Call to system
/ 是否有特定格式或名称调用 /
.data
prompt: .asciiz "What's your name? " #prompt user for name
name: .space 82 #directive to initialize number of characters in string
greeting: .asciiz "Hello, <name> ."
endl: .asciiz "\n"
答案 0 :(得分:0)
这是编辑后的完整代码:
enter code here
.text
.globl main
main:
la $a0, prompt # load address of prompt into a0
li $v0, 4 # load instruction number to display string into v0
syscall # system call to print the prompt call
li $a1, 81 # set string length
la $a0, name # get address of string variable
li $v0, 8 # service call number for reading string from keyboard
syscall # Read string
la $a0, greeting# Display the greeting message
li $v0, 4 # load address of greeting into a0
syscall # call to system to print greeting call
move $t0, $v0 # Moveing name from v0 into t0 for safe keeping
la $a0, name # load address of name into a0
li $v0, 4 # load call code to display string into v0
syscall # call to system to print name
la $a0, endl # load new line into a0
li $v0, 4 # load call code number to display the string into v0
syscall # call to system to print new line
li $v0, 10 # End of greeting program
syscall # Call to system
###################数据段
.data
prompt: .asciiz " What's your name? " #prompt user for name
name: .space 82 #directive to initialize number of characters in string
greeting: .asciiz " Hello, " # Display input next to Hello
endl: .asciiz "\n"
我打电话问候后,我只需要打电话给姓名 感谢Michael指点系统调用4.