SPARC使用scanf()读取字符

时间:2012-11-22 03:36:49

标签: c input sparc

好的,这是我的问题。我正在尝试使用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();

 }

0 个答案:

没有答案