CST250 Project 1: Simple Calculator Learning Objectives: Become familiar with PL
ID: 3679907 • Letter: C
Question
CST250 Project 1: Simple Calculator
Learning Objectives:
Become familiar with PLPTool features
Use PLP arithmetic instructions
Use PLP control flow instructions
The Task:
This lab will be done individually. Your program should start by loading the numbers 2015 and 250 into registers
$a0 and $a1 respectively. The start of your program is a good place to initialize any other registers with values
that you don’t plan on changing inside the program. It should then have an infinite loop that performs two steps:
reading the value of the switches and use control flow instructions to perform the indicated arithmetic operation.
The result should be stored in register $v0. After doing this it should return to the start of the loop and repeat
these two steps. If an undefined switch value is read (i.e. it is not one of the switch values given below), $v0
should contain 0. Use the following switch convention:
Switch Number Hexadecimal Switch Value Binary Switch Value Operation Result ($v0)
0 0x00000001 0b00000001 $v0 = $a0 + $a1 2265
1 0x00000002 0b00000010 $v0 = $a0 - $a1 1765
2 0x00000004 0b00000100 $v0 = $a0 * $a1 503750
3 0x00000008 0b00001000 $v0 = $a0 AND $a1 218
4 0x00000010 0b00010000 $v0 = $a0 OR $a1 2047
Other Other Other $v0 = 0 0
Explanation / Answer
Ltext0: .section .rodata .align 8 .LC0: 0000 456E7465 .string "Enter operator either + or - or * or divide : " 72206F70 65726174 6F722065 69746865 .LC1: 002f 256300 .string "%c" .LC2: 0032 456E7465 .string "Enter two operands: " 72207477 6F206F70 6572616E 64733A20 .LC3: 0047 25662566 .string "%f%f" 00 .LC4: 004c 252E3166 .string "%.1f + %.1f = %.1f" 202B2025 2E316620 3D20252E 316600 .LC5: 005f 252E3166 .string "%.1f - %.1f = %.1f" 202D2025 2E316620 3D20252E 316600 .LC6: 0072 252E3166 .string "%.1f * %.1f = %.1f" 202A2025 2E316620 3D20252E 316600 .LC7: 0085 252E3166 .string "%.1f / %.1f = %.1f" 202F2025 2E316620 3D20252E 316600 .align 8 .LC8: 0098 4572726F .string "Error! operator is not correct" 7221206F 70657261 746F7220 6973206E .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 4883EC10 subq $16, %rsp 0008 BF000000 movl $.LC0, %edi 00 000d B8000000 movl $0, %eax 00 0012 E8000000 call printf 00 0017 488D45F7 leaq -9(%rbp), %rax 001b 4889C6 movq %rax, %rsi 001e BF000000 movl $.LC1, %edi 00 0023 B8000000 movl $0, %eax 00 0028 E8000000 call __isoc99_scanf 00 002d BF000000 movl $.LC2, %edi 00 0032 B8000000 movl $0, %eax 00 0037 E8000000 call printf 00 003c 488D55FC leaq -4(%rbp), %rdx 0040 488D45F8 leaq -8(%rbp), %rax 0044 4889C6 movq %rax, %rsi 0047 BF000000 movl $.LC3, %edi 00 004c B8000000 movl $0, %eax 00 0051 E8000000 call __isoc99_scanf 00 0056 0FB645F7 movzbl -9(%rbp), %eax 005a 0FBEC0 movsbl %al, %eax 005d 83F82B cmpl $43, %eax 0060 7426 je .L3 0062 83F82B cmpl $43, %eax 0065 7F0E jg .L4 0067 83F82A cmpl $42, %eax 006a 0F849400 je .L5 0000 0070 E9050100 jmp .L2 00 .L4: 0075 83F82D cmpl $45, %eax 0078 744C je .L6 007a 83F82F cmpl $47, %eax 007d 0F84BC00 je .L7 0000 0083 E9F20000 jmp .L2 00 .L3: 0088 F30F104D movss -8(%rbp), %xmm1 F8 008d F30F1045 movss -4(%rbp), %xmm0 FC 0092 F30F58C1 addss %xmm1, %xmm0 0096 0F14C0 unpcklps %xmm0, %xmm0 0099 0F5AD0 cvtps2pd %xmm0, %xmm2 009c F30F1045 movss -4(%rbp), %xmm0 FC 00a1 0F14C0 unpcklps %xmm0, %xmm0 00a4 0F5AC8 cvtps2pd %xmm0, %xmm1 00a7 F30F1045 movss -8(%rbp), %xmm0 F8 00ac 0F14C0 unpcklps %xmm0, %xmm0 00af 0F5AC0 cvtps2pd %xmm0, %xmm0 00b2 BF000000 movl $.LC4, %edi 00 00b7 B8030000 movl $3, %eax 00 00bc E8000000 call printf 00 00c1 E9C40000 jmp .L8 00 .L6: 00c6 F30F1045 movss -8(%rbp), %xmm0 F8 00cb F30F104D movss -4(%rbp), %xmm1 FC 00d0 F30F5CC1 subss %xmm1, %xmm0 00d4 0F14C0 unpcklps %xmm0, %xmm0 00d7 0F5AD0 cvtps2pd %xmm0, %xmm2 00da F30F1045 movss -4(%rbp), %xmm0 FC 00df 0F14C0 unpcklps %xmm0, %xmm0 00e2 0F5AC8 cvtps2pd %xmm0, %xmm1 00e5 F30F1045 movss -8(%rbp), %xmm0 F8 00ea 0F14C0 unpcklps %xmm0, %xmm0 00ed 0F5AC0 cvtps2pd %xmm0, %xmm0 00f0 BF000000 movl $.LC5, %edi 00 00f5 B8030000 movl $3, %eax 00 00fa E8000000 call printf 00 00ff E9860000 jmp .L8 00 .L5: 0104 F30F104D movss -8(%rbp), %xmm1 F8 0109 F30F1045 movss -4(%rbp), %xmm0 FC 010e F30F59C1 mulss %xmm1, %xmm0 0112 0F14C0 unpcklps %xmm0, %xmm0 0115 0F5AD0 cvtps2pd %xmm0, %xmm2 0118 F30F1045 movss -4(%rbp), %xmm0 FC 011d 0F14C0 unpcklps %xmm0, %xmm0 0120 0F5AC8 cvtps2pd %xmm0, %xmm1 0123 F30F1045 movss -8(%rbp), %xmm0 F8 0128 0F14C0 unpcklps %xmm0, %xmm0 012b 0F5AC0 cvtps2pd %xmm0, %xmm0 012e BF000000 movl $.LC6, %edi 00 0133 B8030000 movl $3, %eax 00 0138 E8000000 call printf 00 013d EB4B jmp .L8 .L7: 013f F30F1045 movss -8(%rbp), %xmm0 F8 0144 F30F104D movss -4(%rbp), %xmm1 FC 0149 F30F5EC1 divss %xmm1, %xmm0 014d 0F14C0 unpcklps %xmm0, %xmm0 0150 0F5AD0 cvtps2pd %xmm0, %xmm2 0153 F30F1045 movss -4(%rbp), %xmm0 FC 0158 0F14C0 unpcklps %xmm0, %xmm0 015b 0F5AC8 cvtps2pd %xmm0, %xmm1 015e F30F1045 movss -8(%rbp), %xmm0 F8 0163 0F14C0 unpcklps %xmm0, %xmm0 0166 0F5AC0 cvtps2pd %xmm0, %xmm0 0169 BF000000 movl $.LC7, %edi 00 016e B8030000 movl $3, %eax 00 0173 E8000000 call printf 00 0178 EB10 jmp .L8 .L2: 017a BF000000 movl $.LC8, %edi 00 017f B8000000 movl $0, %eax 00 0184 E8000000 call printf 00 0189 90 nop .L8: 018a B8000000 movl $0, %eax 00 018f C9 leave .cfi_def_cfa 7, 8 0190 C3 ret .cfi_endproc .LFE0: .Letext0: