SPARC 어셈블리 언어- 화씨온도를 섭씨온도로 바꾸기
학교 과제 2022. 12. 2. 23:15

.section ".data" a: .double 0r5.0 b: .double 0r9.0 c: .double 0r32.0 .section ".text" fmtp1: .asciz "화씨온도를 입력하시오: " fmts: .asciz "%lf" fmtp2: .asciz "섭씨온도는 %f입니다.\n" .align 4 .global main, printf, scanf main: save %sp, -(92+8)&-8, %sp set fmtp1, %o0 call printf nop set fmts, %o0 add %fp, -8, %o1 call scanf nop ld [%fp-8], %o0 ld [%fp-4], %o1 call ftoc nop st %f0, [%fp-16] st %f1, [%fp-12] set fm..

SPARC 어셈블리 언어- 최대공약수
학교 과제 2022. 12. 2. 23:14

fmt1: .asciz "두 정수를 입력하세요: " fmts: .asciz "%d" fmtp: .asciz "최대공약수는 %d입니다.\n" .align 4 .global main main: save %sp, -96, %sp set fmt1, %o0 call printf nop set fmts, %o0 call scanf add %fp, -4, %o1 nop ld [%fp-4],%l0 ! %l0가 입력받은 첫 수 = a nop set fmts, %o0 call scanf add %fp, -8, %o1 nop ld [%fp-8],%l1 ! %l0가 입력받은 두번째 수 = b nop mov 1, %l2 ! int flag = 1 loop: subcc %l0, %l1, %g0 ! l0 - l1 = l3 = a ..

SPARC 어셈블리 언어- 윤년과 평년
학교 과제 2022. 12. 2. 23:13

fmt1: .asciz "년도를 입력하세요(종료:음수) " fmts: .asciz "%d" fmt2: .asciz "%d 윤년입니다.\n" fmt3: .asciz "%d 평년입니다.\n" .align 4 .global main main: save %sp, -96, %sp loop: set fmt1, %o0 call printf nop set fmts, %o0 call scanf add %fp, -4, %o1 nop ld [%fp-4], %l0 ! %l0가 입력받은 해 ba test nop test: cmp %l0, 0 bl Exit ! 음수일 경우 종료 mov %l0, %o0 ! 400으로 나누어지는 경우 윤년 mov 400, %o1 call .rem nop mov %o0, %l1 cmp %l1, 0 b..

알고리즘 분석 - 트리
학교 과제 2021. 11. 24. 23:06

이진트리에서 왼쪽 서브트리의 노드 개수가 오른쪽 서브트리의 노드 개수보다 작은 노드의 개수 구하기 이진트리에서 노드 i의 왼쪽 서브트리의 노드 개수를 Left(i)라 하고 오른쪽 서브트리의 노드 개수를 Right(i)라 할 때, Left(i) < Right(i)인 노드 i의 개수를 구하는 알고리즘을 재귀법(recursion)을 사용해서 작성하기 #include #include #include using namespace std; int tree[1001][2] = {-1, }; int ans = 0; int l = 0; int r = 0; int height(int root) { if(root == -1) return 0; int hLeft = height(tree[root][0]); int hRight..

SPARC 어셈블리 언어- 문자열 출력
학교 과제 2021. 10. 9. 21:32

구현 srl로 8bit씩 shift하며 출력할 수 있다. fmt1: .asciz "4개의 영문자 입력 : " fmts: .asciz "%s" fmt2: .asciz "%dth 문자 = %c\n" .align 4 .global main main: save %sp, -96, %sp set fmt1, %o0 call printf nop set fmts, %o0 call scanf add %fp, -4, %o1 nop mov 4, %o1 ld [%fp-4], %o2 set fmt2, %o0 call printf nop ld [%fp-4], %o1 srl %o1, 8, %l0 mov 3, %o1 mov %l0, %o2 set fmt2, %o0 call printf nop ld [%fp-4], %o1 srl %o1..