SPARC使用scanf()读取字符
好吧,这是我的问题。我正在尝试使用scanf从用户输入中获取一个字符,并在SPARC汇编中将其打印出来。这段代码比我实际想做的要简单,但这正是我所挂断的东西。它可以很好地处理字符串,但由于某些原因不能处理字符 SPARC代码:SPARC使用scanf()读取字符,c,input,sparc,C,Input,Sparc,好吧,这是我的问题。我正在尝试使用scanf从用户输入中获取一个字符,并在SPARC汇编中将其打印出来。这段代码比我实际想做的要简单,但这正是我所挂断的东西。它可以很好地处理字符串,但由于某些原因不能处理字符 SPARC代码: .section ".data" prompt: .asciz "\nPlease enter your name: " format: .asciz "%c" format2: .asciz "Your name is:%c\n"
.section ".data"
prompt: .asciz "\nPlease enter your name: "
format: .asciz "%c"
format2: .asciz "Your name is:%c\n"
/* Program starts */
.align 4
.section ".text"
.global fun
fun:
save %sp, -96, %sp ! save the stack
set prompt, %o0 ! point o0 to the prompt
call printf ! call printf to print the prompt
nop
set format, %o0 ! point o0 to the input format string
set ch, %o1 ! point o1 at the input variable
call scanf ! get the input into this variable
nop
set format2, %o0 ! point o0 to the output format
set ch, %o1 ! point o1 to the string to be displayed
call printf ! print the string pointed by o1
nop
ret ! return
restore ! get out
C代码:
#include <stdio.h>
char ch;
int main()
{
fun();
}
如果使用C编写代码,并比较扫描字符串和扫描字符之间的scanf调用,您将看到有两个区别:格式和传递目标参数的方式。您是否修改了汇编器代码以适应参数传递中的差异?@Joachim Pileborg我已将格式更改为%c,如您所见,我使用的是在c代码中定义的全局变量ch的地址。这些是唯一的区别吗?我以为他们是。