본문 바로가기
Programming/SPARC

[SPARC] 표준 입출력과 파일 입출력

by 생각하는달팽이 2015. 8. 27.

 

 

 

 

 

아래는 결과화면입니다.

 

 

실제 A889056 이라는 제 학번으로 파일명이 나왔습니다.

해당 파일안에 내용을 출력해보니.

위의 내용이 그대로 출력되었습니다.


 


! TIP : 메모리 사용을 잘해야합니다.

 

 


아래는 소스코드입니다. (_ _)




.section ".data"

fType: .asciz "ab+"

movie: .skip 32*5

grade: .skip 16*5

price: .single 0r7.99,0r7.60,0r8.30,0r7.70,0r8.00

taxRate: .single 0r0.05

membershipRate: .single 0r0.2

disFloat: .single 0r0.005

timetable: .skip 16*5

id: .skip 8

userMovieSelect: .word 0

userMovieYear: .skip 8

userMovieMonth: .skip 4

userMovieDay: .skip 4

userMovieTimeSelect: .word 0

userRow: .skip 4

userNo: .skip 4

.section ".text"

movie_s = 32

grade_s = 16

price_s = 8

timetable_s = 16

movie0: .asciz "The Hnger Games: Catching Fire"

movie1: .asciz "Love Letter"

movie2: .asciz "Gravity"

movie3: .asciz "The Fives"

movie4: .asciz "The Counselor"

grade0: .asciz "PG-13 rating"

grade1: .asciz "G rating"

grade2: .asciz "PG-13 rating"

grade3: .asciz "NC-17 rating"

grade4: .asciz "R rating"

timetable0: .asciz "1st 09:20-11:00"

timetable1: .asciz "2nd 12:50-14:40"

timetable2: .asciz "3rd 15:00-17:00"

timetable3: .asciz "4th 17:30-19:30"

timetable4: .asciz "5th 22:00-00:00"

print_0: .asciz "- Your class Number : "

print_1: .asciz "- Choose a movie of the five\n"

print_2: .asciz "%d. %s (%s,%.2f$)\n"

print_3: .asciz "Number > "

print_4: .asciz "- Input the date for reservation\n"

print_year: .asciz "Year : "

print_month: .asciz "Month : "

print_day: .asciz "Day : "

print_showtime: .asciz "- Choose a show times\n"

print_showtimelabel: .asciz "%d. %s\n"

scanf_0: .asciz "%s"

scanf_1: .asciz "%d"

scanf_2: .asciz "%c"

print_final_top: .asciz "\nTicket Information\n===================================\nSPARC CINEMA\n\n%s\n(%s)\n\n"

print_file_top: .asciz "===================================\nSPARC CINEMA\n\n%s\n(%s)\n\n"

print_price: .asciz "%.2f$ (Tax %.2f$)\n\n" ! 0:userMovieTitle,1:movieGrade,2:movie Price,3:Tax

print_final_bottom: .asciz "%s-%s-%s\n%s\n"

print_theater: .asciz "Theater 1    Row %s    No. %s\n\n"

print_membership: .asciz "[Membership Point]\nCinemaP    :+%.2f\n===================================\n"

.align 4

.global main,printf,scanf,vfprintf

main: save %sp,-96,%sp

call setMovie

nop

call setGrade

nop

call setTimetable

nop

set print_0,%o0

call printf

nop

set id,%o1

set scanf_0,%o0

call scanf

nop ! Finish Get ID (ex:A889056)

set print_1,%o0

call printf

nop

call setRowNo

nop

set movie,%o0

mov movie_s,%o1

set grade,%o2

mov grade_s,%o3

call printMovieList

nop

set userMovieSelect,%o0

call setUserSelection ! Set User Selection

nop

call setReservationDate

nop

call printTimeList

nop

set userMovieTimeSelect,%o0

call setUserSelection ! Set User Selection

nop

call printTicket

nop

test:ret

restore

printTicket:save %sp,-96,%sp

set id,%o0

set fType,%o1

call fopen

nop

mov %o0,%l6 ! this is File Pointer

! 0:userMovieTitle,1:movieGrade,2:movie Price,3:Tax

set print_final_top,%o0

set movie,%l2

set userMovieSelect,%l0

ld [%l0],%l0

sll %l0,5,%l0 ! this is number of movie title

add %l2,%l0,%l2 ! this is select movie title

ld [%l2],%o1

set grade,%l2

set userMovieSelect,%l0

ld [%l0],%l0

sll %l0,4,%l0 ! this is number of movie grade

add %l2,%l0,%l2 ! this is select movie grade

ld [%l2],%o2

call printf

nop

set movie,%l2

set userMovieSelect,%l0

ld [%l0],%l0

sll %l0,5,%l0 ! this is number of movie title

add %l2,%l0,%l2 ! this is select movie title

ld [%l2],%o2

set grade,%l2

set userMovieSelect,%l0

ld [%l0],%l0

sll %l0,4,%l0 ! this is number of movie grade

add %l2,%l0,%l2 ! this is select movie grade

ld [%l2],%o3

set print_file_top,%o1

mov %l6,%o0

call fprintf

nop

set price,%l2

set taxRate,%l3

set disFloat,%l4

set userMovieSelect,%l0

ld [%l0],%l0

sll %l0,2,%l0 

add %l2,%l0,%l2 

ld [%l2],%f0

ld [%l3],%f2

ld [%l4],%f4

fstod %f0,%f0

fstod %f2,%f2

fstod %f4,%f4

fmuld %f0,%f2,%f2

fsubd %f2,%f4,%f2

   std %f0,[%fp-16]

   ldd [%fp-16],%o4 ! this is select movie price 

   mov %o4,%o1

   std %f2,[%fp-16]

   ldd [%fp-16],%o4

   mov %o4,%o3

   set print_price,%o0

   call printf

   nop

   set price,%l2

set taxRate,%l3

set disFloat,%l4

set userMovieSelect,%l0

ld [%l0],%l0

sll %l0,2,%l0 

add %l2,%l0,%l2 

ld [%l2],%f0

ld [%l3],%f2

ld [%l4],%f4

fstod %f0,%f0

fstod %f2,%f2

fstod %f4,%f4

fmuld %f0,%f2,%f2

fsubd %f2,%f4,%f2

   std %f0,[%fp-16]

   ldd [%fp-16],%o2 ! this is select movie price 

   std %f2,[%fp-16]

   ldd [%fp-16],%o4

   set print_price,%o1

   mov %l6,%o0

call fprintf

nop

   set print_final_bottom,%o0

   set userMovieYear,%o1

   set userMovieMonth,%o2

   set userMovieDay,%o3

   set timetable,%l2

set userMovieTimeSelect,%l0

ld [%l0],%l0

sll %l0,4,%l0 ! this is number of movie grade

add %l2,%l0,%l2 ! this is select movie grade

ld [%l2],%o4

call printf

nop

set print_final_bottom,%o1

   set userMovieYear,%o2

   set userMovieMonth,%o3

   set userMovieDay,%o4

   set timetable,%l2

set userMovieTimeSelect,%l0

ld [%l0],%l0

sll %l0,4,%l0 ! this is number of movie grade

add %l2,%l0,%l2 ! this is select movie grade

ld [%l2],%o5

mov %l6,%o0

call fprintf

nop

set print_theater,%o0

set userRow,%o1

set userNo,%o2

call printf

nop

set print_theater,%o1

set userRow,%o2

set userNo,%o3

mov %l6,%o0

call fprintf

nop

set print_membership,%o0

set price,%l2

set membershipRate,%l3

set userMovieSelect,%l0

set disFloat,%l4

ld [%l0],%l0

sll %l0,2,%l0 

add %l2,%l0,%l2 

ld [%l2],%f0

ld [%l3],%f2

ld [%l4],%f4

fstod %f0,%f0

fstod %f2,%f2

fstod %f4,%f4

fmuld %f0,%f2,%f2

fsubd %f2,%f4,%f2

   std %f2,[%fp-16]

   ldd [%fp-16],%o4 ! this is select movie price 

   mov %o4,%o1

   call printf

   nop

set print_membership,%o1

set price,%l2

set membershipRate,%l3

set disFloat,%l4

set userMovieSelect,%l0

ld [%l0],%l0

sll %l0,2,%l0 

add %l2,%l0,%l2 

ld [%l2],%f0

ld [%l3],%f2

ld [%l4],%f4

fstod %f0,%f0

fstod %f2,%f2

fstod %f4,%f4

fmuld %f0,%f2,%f2

fsubd %f2,%f4,%f2

   std %f2,[%fp-16]

   ldd [%fp-16],%o4 ! this is select movie price    

   mov %o4,%o2

   mov %l6,%o0

call fprintf

nop

mov %l6,%o0

call fclose

nop

ret

restore

printTimeList: save %sp,-96,%sp

  clr %l0

  set timetable,%l1

  set print_showtime,%o0

  call printf

  nop

printTimeLoop: inc %l0

  set print_showtimelabel,%o0

  mov %l0,%o1

  ld [%l1],%o2

  call printf

  nop

  add %l1,16,%l1

  cmp %l0,5

  bl printTimeLoop

  nop

  ret

  restore

 

printMovieList: save %sp,-96,%sp

  clr %l0

  set price,%l1

printMovieLoop: inc %l0

  set print_2,%o0

  mov %l0,%o1

  ld [%i0],%o2

  ld [%i2],%o3

  ld [%l1],%f0

  fstod %f0,%f0

  std %f0,[%fp-16]

  ldd [%fp-16],%o4

  call printf

  nop

  add %i0,%i1,%i0

  add %i2,%i3,%i2

  add %l1,4,%l1

  cmp %l0,5

  bl printMovieLoop

  nop

  ret

  restore

setUserSelection: save %sp,-96,%sp

 set print_3,%o0

 call printf

 nop

 set scanf_1,%o0

 add %fp,-4,%o1

 call scanf

 nop

 ld [%fp-4],%l0 ! select movie Number

 set movie,%l2

 sub %l0,1,%l0

 !sll %l0,5,%l0 ! this is number of movie title

 !add %l2,%l0,%l2 ! this is select movie title

 mov %i0,%o1 ! save movie number of selection_0

 st %l0,[%o1] ! save movie number of selection_1

 ret

 restore

setReservationDate: save %sp,-96,%sp

set print_4,%o0

call printf

nop

set print_year,%o0

call printf

nop

set scanf_0,%o0

set userMovieYear,%o1

call scanf

nop

set print_month,%o0

call printf

nop

set scanf_0,%o0

set userMovieMonth,%o1

call scanf

nop

set print_day,%o0

call printf

nop

set scanf_0,%o0

set userMovieDay,%o1

call scanf

nop

ret

restore

setMovie: save %sp,-96,%sp ! Movie Title Set Methods

  set movie,%l1 

set movie0,%l2

st %l2,[%l1]

set movie1,%l2

st %l2,[%l1+32]

set movie2,%l2

st %l2,[%l1+64]

set movie3,%l2

st %l2,[%l1+96]

set movie4,%l2

st %l2,[%l1+128]

    ret

    restore

setGrade: save %sp,-96,%sp ! Grade Set Methods

  set grade,%l1 

set grade0,%l2

st %l2,[%l1]

set grade1,%l2

st %l2,[%l1+16]

set grade2,%l2

st %l2,[%l1+32]

set grade3,%l2

st %l2,[%l1+48]

set grade4,%l2

st %l2,[%l1+64]

    ret

    restore

setTimetable:save %sp,-96,%sp ! TimeTable Set Methods

  set timetable,%l1 

set timetable0,%l2

st %l2,[%l1]

set timetable1,%l2

st %l2,[%l1+16]

set timetable2,%l2

st %l2,[%l1+32]

set timetable3,%l2

st %l2,[%l1+48]

set timetable4,%l2

st %l2,[%l1+64]

    ret

    restore

setRowNo: save %sp,-96,%sp

 set id,%l0

 set userRow,%l1

 set userNo,%l2

 ldsb [%l0],%l3

 stb %l3,[%l1]

 ldsb [%l0+1],%l3

 stb %l3,[%l1+1]

 ldsb [%l0+4],%l3

 stb %l3,[%l2]

 ldsb [%l0+5],%l3

 stb %l3,[%l2+1]

 ldsb [%l0+6],%l3

 stb %l3,[%l2+2]

 ret

 restore


 

 

반응형

'Programming > SPARC' 카테고리의 다른 글

[SPARC] 비트처리 연산  (2) 2015.08.27
[SPARC] 부동소수점 매개변수 전달  (0) 2015.08.27
[SPARC] A5/암호화  (0) 2015.08.27