1

好的,这是我的问题。我正在尝试使用 scanf() 从用户输入中获取一个字符,然后在 SPARC Assembly 中将其打印回给他们。这段代码比我实际尝试做的要简单,但这是我挂断的事情。它适用于字符串,但由于某种原因不适用于字符。

SPARC 代码:

  .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();

 }
4

0 回答 0