Objectives: -write assembly language programs to: -perform arithmetic on floatin
ID: 3768067 • Letter: O
Question
Objectives:
-write assembly language programs to:
-perform arithmetic on floating point numbers
-use syscall operations to display floating point numbers and strings on the console window
-use syscall operations to read floating point numbers from the keyboard.
Assignment Description:
Write a MIPS assembly language program that prompts for a user to enter a series of floating point numbers and calls read_float to read in numbers and store them in an array only if the same number is not stored in the array yet. Then the program should display the array content on the console window.
Consult the green sheet and the chapter 3 for assembly instructions for floating point numbers. Here is one instruction that you might use:
c.eq.s $f2, $f4
bc1t Label1
Here if the value in the register $f2 is equals to the value in $f4, it jumps to the Label1. If it should jump when the value in the register $f2 is NOT equals to the value in $f4, then it should be:
c.eq.s $f2, $f4
bc1f Label1
To load a single precision floating point number (instead of lw for an integer), you might use:
l.s $f12, 0($t0)
To store a single precision floating point number (instead of sw for an integer), you might use:
s.s $f12, 0($t0)
To assign a constant floating point number (instead of li for an integer), you might use:
li.s $f12, 123.45
To copy a floating point number from one register to another (instead of move for an integer), you might use:
mov.s $f10, $f12
The following shows the syscall numbers needed for this assignment.
System Call System Call System Call
Number Operation Description
2 print_float $v0 = 2, $f12 = float number to be printed
4 print_string $v0 = 4, $a0 = address of beginning of ASCIIZ string
6 read_float $v0 = 6; user types a float number at keyboard; value is store in $f0
8 read_string $v0 = 8; user types string at keybd; addr of beginning of string is store in $a0; len in $a1
Here are sample outputs (user input is in bold): -- note that you might get some rounding errors
Enter a number:
3
Enter a number:
54.4
Enter a number:
2
Enter a number:
5
Enter a number:
2
Enter a number:
-4
Enter a number:
5
Enter a number:
76
Enter a number:
-23
Enter a number:
43.53
Enter a number:
-43.53
Enter a number:
43.53
Enter a number:
65.43
The array contains the following:
3.00000000
54.40000153
2.00000000
5.00000000
-4.00000000
76.00000000
-23.00000000
43.52999878
-43.52999878
65.43000031
--------------------------------------------
Explanation / Answer
.Ltext0: .section .rodata .LC0: 0000 456E7465 .string "Enter a number:" 72206120 6E756D62 65723A00 .LC1: 0010 256600 .string "%f" 0013 00000000 .align 8 00 .LC2: 0018 54686520 .string "The array contains the following:" 61727261 7920636F 6E746169 6E732074 .LC3: 003a 25660A00 .string "%f " .text .globl main main: .LFB0: .cfi_startproc 0000 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0001 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0004 53 pushq %rbx 0005 4883EC38 subq $56, %rsp .cfi_offset 3, -24 0009 4889E0 movq %rsp, %rax 000c 4889C3 movq %rax, %rbx 000f C745DC0A movl $10, -36(%rbp) 000000 0016 8B45DC movl -36(%rbp), %eax 0019 4C63C0 movslq %eax, %r8 001c 4983E801 subq $1, %r8 0020 4C8945E0 movq %r8, -32(%rbp) 0024 4C63C0 movslq %eax, %r8 0027 4C89C6 movq %r8, %rsi 002a BF000000 movl $0, %edi 00 002f 4863F0 movslq %eax, %rsi 0032 4889F2 movq %rsi, %rdx 0035 B9000000 movl $0, %ecx 00 003a 4898 cltq 003c 48C1E002 salq $2, %rax 0040 488D5003 leaq 3(%rax), %rdx 0044 B8100000 movl $16, %eax 00 0049 4883E801 subq $1, %rax 004d 4801D0 addq %rdx, %rax 0050 B9100000 movl $16, %ecx 00 0055 BA000000 movl $0, %edx 00 005a 48F7F1 divq %rcx 005d 486BC010 imulq $16, %rax, %rax 0061 4829C4 subq %rax, %rsp 0064 4889E0 movq %rsp, %rax 0067 4883C003 addq $3, %rax 006b 48C1E802 shrq $2, %rax 006f 48C1E002 salq $2, %rax 0073 488945E8 movq %rax, -24(%rbp) 0077 C745D000 movl $0, -48(%rbp) 000000 007e EB7B jmp .L2 .L7: .LBB2: 0080 BF000000 movl $.LC0, %edi 00 0085 E8000000 call puts 00 008a 488D45CC leaq -52(%rbp), %rax 008e 4889C6 movq %rax, %rsi 0091 BF000000 movl $.LC1, %edi 00 0096 B8000000 movl $0, %eax 00 009b E8000000 call scanf 00 00a0 C745D800 movl $0, -40(%rbp) 000000 00a7 C745D400 movl $0, -44(%rbp) 000000 00ae EB29 jmp .L3 .L6: 00b0 488B45E8 movq -24(%rbp), %rax 00b4 8B55D4 movl -44(%rbp), %edx 00b7 4863D2 movslq %edx, %rdx 00ba F30F1004 movss (%rax,%rdx,4), %xmm0 90 00bf F30F104D movss -52(%rbp), %xmm1 CC 00c4 0F2EC1 ucomiss %xmm1, %xmm0 00c7 7A0C jp .L4 00c9 0F2EC1 ucomiss %xmm1, %xmm0 00cc 7507 jne .L4 00ce C745D801 movl $1, -40(%rbp) 000000 .L4: 00d5 8345D401 addl $1, -44(%rbp) .L3: 00d9 8B45D4 movl -44(%rbp), %eax 00dc 3B45D0 cmpl -48(%rbp), %eax 00df 7CCF jl .L6 00e1 837DD800 cmpl $0, -40(%rbp) 00e5 7514 jne .L2 00e7 8B45CC movl -52(%rbp), %eax 00ea 488B55E8 movq -24(%rbp), %rdx 00ee 8B4DD0 movl -48(%rbp), %ecx 00f1 4863C9 movslq %ecx, %rcx 00f4 89048A movl %eax, (%rdx,%rcx,4) 00f7 8345D001 addl $1, -48(%rbp) .L2: .LBE2: 00fb 8B45D0 movl -48(%rbp), %eax 00fe 3B45DC cmpl -36(%rbp), %eax 0101 0F8C79FF jl .L7 FFFF 0107 BF000000 movl $.LC2, %edi 00 010c E8000000 call puts 00 0111 C745D000 movl $0, -48(%rbp) 000000 0118 EB28 jmp .L8 .L9: 011a 488B45E8 movq -24(%rbp), %rax 011e 8B55D0 movl -48(%rbp), %edx 0121 4863D2 movslq %edx, %rdx 0124 F30F1004 movss (%rax,%rdx,4), %xmm0 90 0129 0F14C0 unpcklps %xmm0, %xmm0 012c 0F5AC0 cvtps2pd %xmm0, %xmm0 012f BF000000 movl $.LC3, %edi 00 0134 B8010000 movl $1, %eax 00 0139 E8000000 call printf 00 013e 8345D001 addl $1, -48(%rbp) .L8: 0142 8B45D0 movl -48(%rbp), %eax 0145 3B45DC cmpl -36(%rbp), %eax 0148 7CD0 jl .L9 014a 90 nop 014b 4889DC movq %rbx, %rsp 014e 488B5DF8 movq -8(%rbp), %rbx 0152 C9 leave .cfi_def_cfa 7, 8 0153 C3 ret .cfi_endproc .LFE0: .Letext0:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.