IO in SPARC - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

IO in SPARC

Description:

o0 must be containing the address of a null terminated string (c-string). A null terminated string is a string ended with 1 byte zero. For example: !in your data ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 14
Provided by: mah138
Category:

less

Transcript and Presenter's Notes

Title: IO in SPARC


1
I/O in SPARC
2
  • In SPARC, using system call printf and scanf is
    an easy way to perform I/O
  • These functions perform conversion and extraction
    automatically.

3
printf
  • To use printf function, the following must be
    satisfied
  • o0 must be containing the address of a null
    terminated string (c-string). A null terminated
    string is a string ended with 1 byte zero.
  • For example
  • !in your data section
  • myString .asciz hello world!
  • . . .
  • !in your code
  • set myString, o0 ! Get the address
    of the label
  • call printf !this should print hello world!
  • nop

.ascii string Generates the given sequences of
ASCII characters.   .asciz string Generates
the given sequences of ASCII characters. This
pseudo-op appends a null (zero) byte to each
string.
4
  • In C
  • Print(..Hello world)
  • Print(Integer d, someInteger)
  • To print out variables value
  • you must have your register o1-o5 containing
    the values to be substituted

5
  • In C Printf(its d dollars,amount)
  • In SPARC
  • !assuming your string declared as follow
  • myString .asciz its d dollars
  • !In your code
  • set myString, o0 ! The address of the string
  • mov 20, o1 !substitutes for the first d
  • call printf !will print its 20 dollars

6
d or i Decimal signed integer. o Octal
integer. x or X Hex integer. U Unsigned
integer. c Character. s C-String, i.e. null
terminated string. f Double e or E
Double. g or G Double. n Number of characters
written by this printf.
7
  • !assuming your string declared as follow
  • myString .asciz its d dollars and d cents
  • !In your code
  • set myString, o0 ! The address of the string
  • mov 20, o1 ! substituted for the first d
  • mov 5, o2 ! substituted for the second d
  • call printf ! Will print its 20
    dollars and 5 cents

8
  • To print a string, the address of the substituted
    string must be in the correspondent register.
  • For example
  • !assuming your strings are in data section as
    follows
  • mystring .asciz Hello s!
  • name .asciz Michael
  • . . .
  • ! and your code should be
  • set myString, o0 ! address of the output
  • set name, o1 ! Address of the substituted string
  • call printf ! Will print Hello Michael!
  • nop

9
scanf
  • scanf is used for reading user input
  • scanf requires o0 containing the address of a
    c-string containing the input format
  • Subsequence registers (o1-o5) contain the
    address of the memory where the input should be
    stored
  • d and i always give you a 32-bit (word-size)
    input, so the address must be aligned by word
    boundary (aligned by 4)

10
  • d or i Decimal signed integer.
  • o Octal integer.
  • x or X Hex integer.
  • U Unsigned integer.
  • c Character.
  • s C-String, i.e. null terminated string.
  • f Double
  • e or E Double.
  • g or G Double.
  • n Number of characters written by this printf.

11
  • !assuming your strings are in data section as
    follows
  • input .word 0 !aligned by 4
  • format .asciz d
  • . . .
  • ! and your code should be
  • set format, o0 ! Address of the format
  • set input, o1 ! Address of the location for the
    input
  • call scanf ! Reads user input, converts to a
  • nop ! number and stores at the memory !
    referenced by input

12
  • !assuming your strings are in data section as
    follows
  • input .word 0 !aligned by 4
  • nl .byte 0 ! A byte to store the input \n
  • format .asciz dc
  • . . .
  • ! and your code should be
  • set format, o0 ! Address of the format
  • set input, o1 ! Address of the location for the
    input
  • set nl , o2 ! location for a character
  • call scanf ! Reads user input, converts to a
  • nop ! number and stores at the memory !
    referenced by input

13
  • !assuming your strings are in data section as
    follows
  • format .asciz s
  • input .asciz !Allocate
    some space for the input string
  • . . .
  • ! and your code should be
  • set format, o0 ! Address of the format
  • set input, o1 ! Address of the location
    for the input
  • call scanf ! Reads user input
    up to a blank or ENTER key
  • nop
Write a Comment
User Comments (0)
About PowerShow.com