Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this lab you need to write a MIPS program to count the number of occurrences

ID: 3668514 • Letter: I

Question

In this lab you need to write a MIPS program to count the number of occurrences of an integer X in a string of integers S. The integer X and all the integers in S are positive and greater than zero except the "last" integer in the string S, which is zero. That zero acts as a delimiter that marks the end of the string S. Therefore, the number of integers in S is not given as input to your program. The instructions in your program should trace the content of S counting how many integers in the string equal to X. The counting result should be stored in a variable C. Using your text editor, write a MIPS program to solve the above problem and save it in Lab2_Prog. asm. Assume the following: The address of X is stored in $sl The address of C is stored in $s2 The address of the first integer in S is stored in $s3 Make sure the Settings have the "Load exception file" option turned off. Start PCSpim Open your program. You may have to edit and reload if there are errors. Initialize the program counter to 0x00 4 00 000. Initialize the registers and string entries to the values in Table 1:

Explanation / Answer

.Ltext0:

          .local   _ZStL8__ioinit

          .comm   _ZStL8__ioinit,1,1

          .section   .rodata

      .LC0:

0000 456E7465        .string   "Enter a number : "

   72206120

   6E756D62

   6572203A

   2000

      .LC1:

0012 20546865        .string   " The occurrence of "

   206F6363

   75727265

   6E636520

   6F662000

      .LC2:

0026 20697320        .string   " is "

   00

      .LC3:

002b 74696D65        .string   "times"

   7300

          .text

          .globl   main

      main:

      .LFB971:

          .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 4883EC20        subq   $32, %rsp

      .LBB2:

0008 C745F805        movl   $5, -8(%rbp)

   000000

000f BE000000        movl   $.LC0, %esi

   00

0014 BF000000        movl   $_ZSt4cout, %edi

   00

0019 E8000000        call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

   00

001e 488D45EC        leaq   -20(%rbp), %rax

0022 4889C6        movq   %rax, %rsi

0025 BF000000        movl   $_ZSt3cin, %edi

   00

002a E8000000        call   _ZNSirsERi

   00

002f 8B45EC        movl   -20(%rbp), %eax

0032 8945F4        movl   %eax, -12(%rbp)

0035 C745F000        movl   $0, -16(%rbp)

   000000

003c EB4D        jmp   .L2

      .L3:

003e 8B4DF4        movl   -12(%rbp), %ecx

0041 BA676666        movl   $1717986919, %edx

   66

0046 89C8        movl   %ecx, %eax

0048 F7EA        imull   %edx

004a C1FA02        sarl   $2, %edx

004d 89C8        movl   %ecx, %eax

004f C1F81F        sarl   $31, %eax

0052 29C2        subl   %eax, %edx

0054 89D0        movl   %edx, %eax

0056 C1E002        sall   $2, %eax

0059 01D0        addl   %edx, %eax

005b 01C0        addl   %eax, %eax

005d 29C1        subl   %eax, %ecx

005f 89C8        movl   %ecx, %eax

0061 8945FC        movl   %eax, -4(%rbp)

0064 8B4DF4        movl   -12(%rbp), %ecx

0067 BA676666        movl   $1717986919, %edx

   66

006c 89C8        movl   %ecx, %eax

006e F7EA        imull   %edx

0070 C1FA02        sarl   $2, %edx

0073 89C8        movl   %ecx, %eax

0075 C1F81F        sarl   $31, %eax

0078 29C2        subl   %eax, %edx

007a 89D0        movl   %edx, %eax

007c 8945F4        movl   %eax, -12(%rbp)

007f 8B45FC        movl   -4(%rbp), %eax

0082 3B45F8        cmpl   -8(%rbp), %eax

0085 7504        jne   .L2

0087 8345F001        addl   $1, -16(%rbp)

      .L2:

008b 837DF400        cmpl   $0, -12(%rbp)

008f 75AD        jne   .L3

0091 BE000000        movl   $.LC1, %esi

   00

0096 BF000000        movl   $_ZSt4cout, %edi

   00

009b E8000000        call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

   00

00a0 8B55F8        movl   -8(%rbp), %edx

00a3 89D6        movl   %edx, %esi

00a5 4889C7        movq   %rax, %rdi

00a8 E8000000        call   _ZNSolsEi

   00

00ad BE000000        movl   $.LC2, %esi

   00

00b2 4889C7        movq   %rax, %rdi

00b5 E8000000        call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

   00

00ba 8B55F0        movl   -16(%rbp), %edx

00bd 89D6        movl   %edx, %esi

00bf 4889C7        movq   %rax, %rdi

00c2 E8000000        call   _ZNSolsEi

   00

00c7 BE000000        movl   $.LC3, %esi

   00

00cc 4889C7        movq   %rax, %rdi

00cf E8000000        call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc

   00

00d4 B8000000        movl   $0, %eax

   00

      .LBE2:

00d9 C9        leave

          .cfi_def_cfa 7, 8

00da C3        ret

          .cfi_endproc

      .LFE971:

      _Z41__static_initialization_and_destruction_0ii:

      .LFB975:

00f8 BF000000        movl   $_ZStL8__ioinit, %edi

   00

00fd E8000000        call   _ZNSt8ios_base4InitC1Ev

   00

0102 BA000000        movl   $__dso_handle, %edx

   00

0107 BE000000        movl   $_ZStL8__ioinit, %esi

   00

010c BF000000        movl   $_ZNSt8ios_base4InitD1Ev, %edi

   00

0111 E8000000        call   __cxa_atexit

   00

          .cfi_startproc

00db 55        pushq   %rbp

          .cfi_def_cfa_offset 16

          .cfi_offset 6, -16

00dc 4889E5        movq   %rsp, %rbp

          .cfi_def_cfa_register 6

00df 4883EC10        subq   $16, %rsp

00e3 897DFC        movl   %edi, -4(%rbp)

00e6 8975F8        movl   %esi, -8(%rbp)

00e9 837DFC01        cmpl   $1, -4(%rbp)

00ed 7527        jne   .L5

00ef 817DF8FF        cmpl   $65535, -8(%rbp)

   FF0000

00f6 751E        jne   .L5

      .L5:

0116 C9        leave

          .cfi_def_cfa 7, 8

0117 C3        ret

          .cfi_endproc

      .LFE975:

      _GLOBAL__sub_I_main:

      .LFB976:

          .cfi_startproc

0118 55        pushq   %rbp

          .cfi_def_cfa_offset 16

          .cfi_offset 6, -16

0119 4889E5        movq   %rsp, %rbp

          .cfi_def_cfa_register 6

011c BEFFFF00        movl   $65535, %esi

   00

0121 BF010000        movl   $1, %edi

   00

0126 E8B0FFFF        call   _Z41__static_initialization_and_destruction_0ii

   FF

012b 5D        popq   %rbp

          .cfi_def_cfa 7, 8

012c C3        ret

          .cfi_endproc

      .LFE976:

          .section   .init_array,"aw"

          .align 8

0000 00000000        .quad   _GLOBAL__sub_I_main

   00000000

          .text

      .Letext0:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote