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

MIPS 2D Array Allocate storage to store a 3 row by 3 column two dimensional arra

ID: 3840753 • Letter: M

Question

MIPS 2D Array

Allocate storage to store a 3 row by 3 column two dimensional array of integers. Call the array A. Initialize the array with each element’s value as follows: A[0][0] = 1 A[0][1] = 2 A[0][2] = 3 A[1][0] = 4 A[1][1] = 5 A[1][2] = 6 A[2][0] = 7 A[2][1] = 8 A[2][2] = 9 Then, have the program use a loop to continually ask the user to input a pair of integers. The first integer is the row number (row) and the second integer is the column number (column) of an element in the array A. One of these three actions will be performed depending on the value of the row number and column number inputted: 1. If the row number is -1 and the column number is -1 then terminate the loop and the program. 2. Or, check to make sure the row number and column number are valid indices for the array A. A valid index for array A is 0, 1 or 2. If either the row number or the column number (or both) are invalid then do nothing and return to the beginning of the loop to ask for a new pair of numbers. 3. If the row number and the column number are valid indices then load the value of element A[row][column] from memory and print out the value. Then, return to the beginning of the loop to ask for a new pair of numbers.

Explanation / Answer

.file "example.cpp"
.intel_syntax noprefix
.text
.Ltext0:
.section .rodata
.LC0:
.string " Enter the a[%d][%d] = "
.LC1:
.string "%d"
.LC2:
.string "%d "
.text
.globl main
.type main, @function
main:
.LFB0:
.file 1 "/tmp/compiler-explorer-compiler117418-65-1oqoejw.mk5ryhkt9/example.cpp"
.loc 1 3 0
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp
.cfi_def_cfa_register 6
sub rsp, 48
.loc 1 9 0
mov DWORD PTR [rbp-4], 0
.L5:
.loc 1 9 0 is_stmt 0 discriminator 1
cmp DWORD PTR [rbp-4], 2
jg .L2
.loc 1 10 0 is_stmt 1
mov DWORD PTR [rbp-8], 0
.L4:
.loc 1 10 0 is_stmt 0 discriminator 1
cmp DWORD PTR [rbp-8], 2
jg .L3
.loc 1 11 0 is_stmt 1
mov edx, DWORD PTR [rbp-8]
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
.loc 1 12 0
lea rcx, [rbp-48]
mov eax, DWORD PTR [rbp-8]
movsx rsi, eax
mov eax, DWORD PTR [rbp-4]
movsx rdx, eax
mov rax, rdx
add rax, rax
add rax, rdx
add rax, rsi
sal rax, 2
add rax, rcx
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
.loc 1 10 0
add DWORD PTR [rbp-8], 1
jmp .L4
.L3:
.loc 1 9 0 discriminator 2
add DWORD PTR [rbp-4], 1
jmp .L5
.L2:
.loc 1 17 0
mov DWORD PTR [rbp-4], 0
.L9:
.loc 1 17 0 is_stmt 0 discriminator 1
cmp DWORD PTR [rbp-4], 2
jg .L6
.loc 1 18 0 is_stmt 1
mov DWORD PTR [rbp-8], 0
.L8:
.loc 1 18 0 is_stmt 0 discriminator 1
cmp DWORD PTR [rbp-8], 2
jg .L7
.loc 1 19 0 is_stmt 1
mov eax, DWORD PTR [rbp-8]
movsx rcx, eax
mov eax, DWORD PTR [rbp-4]
movsx rdx, eax
mov rax, rdx
add rax, rax
add rax, rdx
add rax, rcx
mov eax, DWORD PTR [rbp-48+rax*4]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
.loc 1 18 0
add DWORD PTR [rbp-8], 1
jmp .L8
.L7:
.loc 1 21 0
mov edi, 10
call putchar
.loc 1 17 0
add DWORD PTR [rbp-4], 1
jmp .L9
.L6:
.loc 1 24 0
mov eax, 0
.loc 1 25 0
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.Letext0:
.file 2 "/opt/compiler-explorer/gcc-6.3.0/lib/gcc/x86_64-linux-gnu/6.3.0/include/stddef.h"
.file 3 "/usr/include/x86_64-linux-gnu/bits/types.h"
.file 4 "/usr/include/libio.h"
.file 5 "/usr/include/stdio.h"
.file 6 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h"
.section .debug_info,"",@progbits
.Ldebug_info0:
.long 0x369
.value 0x4
.long .Ldebug_abbrev0
.byte 0x8
.uleb128 0x1
.long .LASF56
.byte 0x4
.long .LASF57
.long .LASF58
.quad .Ltext0
.quad .Letext0-.Ltext0
.long .Ldebug_line0
.uleb128 0x2
.long .LASF7
.byte 0x2
.byte 0xd8
.long 0x38
.uleb128 0x3
.byte 0x8
.byte 0x7
.long .LASF0
.uleb128 0x3
.byte 0x1
.byte 0x8
.long .LASF1
.uleb128 0x3
.byte 0x2
.byte 0x7
.long .LASF2
.uleb128 0x3
.byte 0x4
.byte 0x7
.long .LASF3
.uleb128 0x3
.byte 0x1
.byte 0x6
.long .LASF4
.uleb128 0x3
.byte 0x2
.byte 0x5
.long .LASF5
.uleb128 0x4
.byte 0x4
.byte 0x5
.string "int"
.uleb128 0x3
.byte 0x8
.byte 0x5
.long .LASF6
.uleb128 0x2
.long .LASF8
.byte 0x3
.byte 0x83
.long 0x69
.uleb128 0x2
.long .LASF9
.byte 0x3
.byte 0x84
.long 0x69
.uleb128 0x3
.byte 0x8
.byte 0x7
.long .LASF10
.uleb128 0x5
.byte 0x8
.uleb128 0x6
.byte 0x8
.long 0x95
.uleb128 0x3
.byte 0x1
.byte 0x6
.long .LASF11
.uleb128 0x7
.long 0x95
.uleb128 0x8
.long .LASF41
.byte 0xd8
.byte 0x4
.byte 0xf1
.long 0x21e
.uleb128 0x9
.long .LASF12
.byte 0x4
.byte 0xf2
.long 0x62
.byte 0
.uleb128 0x9
.long .LASF13
.byte 0x4
.byte 0xf7
.long 0x8f
.byte 0x8
.uleb128 0x9
.long .LASF14
.byte 0x4
.byte 0xf8
.long 0x8f
.byte 0x10
.uleb128 0x9
.long .LASF15
.byte 0x4
.byte 0xf9
.long 0x8f
.byte 0x18
.uleb128 0x9
.long .LASF16
.byte 0x4
.byte 0xfa
.long 0x8f
.byte 0x20
.uleb128 0x9
.long .LASF17
.byte 0x4
.byte 0xfb
.long 0x8f
.byte 0x28
.uleb128 0x9
.long .LASF18
.byte 0x4
.byte 0xfc
.long 0x8f
.byte 0x30
.uleb128 0x9
.long .LASF19
.byte 0x4
.byte 0xfd
.long 0x8f
.byte 0x38
.uleb128 0x9
.long .LASF20
.byte 0x4
.byte 0xfe
.long 0x8f
.byte 0x40
.uleb128 0xa
.long .LASF21
.byte 0x4
.value 0x100
.long 0x8f
.byte 0x48
.uleb128 0xa
.long .LASF22
.byte 0x4
.value 0x101
.long 0x8f
.byte 0x50
.uleb128 0xa
.long .LASF23
.byte 0x4
.value 0x102
.long 0x8f
.byte 0x58
.uleb128 0xa
.long .LASF24
.byte 0x4
.value 0x104
.long 0x256
.byte 0x60
.uleb128 0xa
.long .LASF25
.byte 0x4
.value 0x106
.long 0x25c
.byte 0x68
.uleb128 0xa
.long .LASF26
.byte 0x4
.value 0x108
.long 0x62
.byte 0x70
.uleb128 0xa
.long .LASF27
.byte 0x4
.value 0x10c
.long 0x62
.byte 0x74
.uleb128 0xa
.long .LASF28
.byte 0x4
.value 0x10e
.long 0x70
.byte 0x78
.uleb128 0xa
.long .LASF29
.byte 0x4
.value 0x112
.long 0x46
.byte 0x80
.uleb128 0xa
.long .LASF30
.byte 0x4
.value 0x113
.long 0x54
.byte 0x82
.uleb128 0xa
.long .LASF31
.byte 0x4
.value 0x114
.long 0x262
.byte 0x83
.uleb128 0xa
.long .LASF32
.byte 0x4
.value 0x118
.long 0x272
.byte 0x88
.uleb128 0xa
.long .LASF33
.byte 0x4
.value 0x121
.long 0x7b
.byte 0x90
.uleb128 0xa
.long .LASF34
.byte 0x4
.value 0x129
.long 0x8d
.byte 0x98
.uleb128 0xa
.long .LASF35
.byte 0x4
.value 0x12a
.long 0x8d
.byte 0xa0
.uleb128 0xa
.long .LASF36
.byte 0x4
.value 0x12b
.long 0x8d
.byte 0xa8
.uleb128 0xa
.long .LASF37
.byte 0x4
.value 0x12c
.long 0x8d
.byte 0xb0
.uleb128 0xa
.long .LASF38
.byte 0x4
.value 0x12e
.long 0x2d
.byte 0xb8
.uleb128 0xa
.long .LASF39
.byte 0x4
.value 0x12f
.long 0x62
.byte 0xc0
.uleb128 0xa
.long .LASF40
.byte 0x4
.value 0x131
.long 0x278
.byte 0xc4
.byte 0
.uleb128 0xb
.long .LASF59
.byte 0x4
.byte 0x96
.uleb128 0x8
.long .LASF42
.byte 0x18
.byte 0x4
.byte 0x9c
.long 0x256
.uleb128 0x9
.long .LASF43
.byte 0x4
.byte 0x9d
.long 0x256
.byte 0
.uleb128 0x9
.long .LASF44
.byte 0x4
.byte 0x9e
.long 0x25c
.byte 0x8
.uleb128 0x9
.long .LASF45
.byte 0x4
.byte 0xa2
.long 0x62
.byte 0x10
.byte 0
.uleb128 0x6
.byte 0x8
.long 0x225
.uleb128 0x6
.byte 0x8
.long 0xa1
.uleb128 0xc
.long 0x95
.long 0x272
.uleb128 0xd
.long 0x86
.byte 0
.byte 0
.uleb128 0x6
.byte 0x8
.long 0x21e
.uleb128 0xc
.long 0x95
.long 0x288
.uleb128 0xd
.long 0x86
.byte 0x13
.byte 0
.uleb128 0xe
.long .LASF60
.uleb128 0xf
.long .LASF46
.byte 0x4
.value 0x13b
.long 0x288
.uleb128 0xf
.long .LASF47
.byte 0x4
.value 0x13c
.long 0x288
.uleb128 0xf
.long .LASF48
.byte 0x4
.value 0x13d
.long 0x288
.uleb128 0x6
.byte 0x8
.long 0x9c
.uleb128 0x7
.long 0x2b1
.uleb128 0x10
.long .LASF49
.byte 0x5
.byte 0xa8
.long 0x25c
.uleb128 0x10
.long .LASF50
.byte 0x5
.byte 0xa9
.long 0x25c
.uleb128 0x10
.long .LASF51
.byte 0x5
.byte 0xaa
.long 0x25c
.uleb128 0x10
.long .LASF52
.byte 0x6
.byte 0x1a
.long 0x62
.uleb128 0xc
.long 0x2b7
.long 0x2f3
.uleb128 0x11
.byte 0
.uleb128 0x10
.long .LASF53
.byte 0x6
.byte 0x1b
.long 0x2e8
.uleb128 0x10
.long .LASF54
.byte 0x6
.byte 0x1e
.long 0x62
.uleb128 0x10
.long .LASF55
.byte 0x6
.byte 0x1f
.long 0x2e8
.uleb128 0x12
.long .LASF61
.byte 0x1
.byte 0x3
.long 0x62
.quad .LFB0
.quad .LFE0-.LFB0
.uleb128 0x1
.byte 0x9c
.long 0x35a
.uleb128 0x13
.string "i"
.byte 0x1
.byte 0x4
.long 0x62
.uleb128 0x2
.byte 0x91
.sleb128 -20
.uleb128 0x13
.string "j"
.byte 0x1
.byte 0x4
.long 0x62
.uleb128 0x2
.byte 0x91
.sleb128 -24
.uleb128 0x13
.string "a"
.byte 0x1
.byte 0x4
.long 0x35a
.uleb128 0x2
.byte 0x91
.sleb128 -64
.byte 0
.uleb128 0x14
.long 0x62
.uleb128 0xd
.long 0x86
.byte 0x2
.uleb128 0xd
.long 0x86
.byte 0x2
.byte 0
.byte 0
.section .debug_abbrev,"",@progbits
.Ldebug_abbrev0:
.uleb128 0x1
.uleb128 0x11
.byte 0x1
.uleb128 0x25
.uleb128 0xe
.uleb128 0x13
.uleb128 0xb
.uleb128 0x3
.uleb128 0xe
.uleb128 0x1b
.uleb128 0xe
.uleb128 0x11
.uleb128 0x1
.uleb128 0x12
.uleb128 0x7
.uleb128 0x10
.uleb128 0x17
.byte 0
.byte 0
.uleb128 0x2
.uleb128 0x16
.byte 0
.uleb128 0x3
.uleb128 0xe
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0xb
.uleb128 0x49
.uleb128 0x13
.byte 0
.byte 0
.uleb128 0x3
.uleb128 0x24
.byte 0
.uleb128 0xb
.uleb128 0xb
.uleb128 0x3e
.uleb128 0xb
.uleb128 0x3
.uleb128 0xe
.byte 0
.byte 0
.uleb128 0x4
.uleb128 0x24
.byte 0
.uleb128 0xb
.uleb128 0xb
.uleb128 0x3e
.uleb128 0xb
.uleb128 0x3
.uleb128 0x8
.byte 0
.byte 0
.uleb128 0x5
.uleb128 0xf
.byte 0
.uleb128 0xb
.uleb128 0xb
.byte 0
.byte 0
.uleb128 0x6
.uleb128 0xf
.byte 0
.uleb128 0xb
.uleb128 0xb
.uleb128 0x49
.uleb128 0x13
.byte 0
.byte 0
.uleb128 0x7
.uleb128 0x26
.byte 0
.uleb128 0x49
.uleb128 0x13
.byte 0
.byte 0
.uleb128 0x8
.uleb128 0x13
.byte 0x1
.uleb128 0x3
.uleb128 0xe
.uleb128 0xb
.uleb128 0xb
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0xb
.uleb128 0x1
.uleb128 0x13
.byte 0
.byte 0
.uleb128 0x9
.uleb128 0xd
.byte 0
.uleb128 0x3
.uleb128 0xe
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0xb
.uleb128 0x49
.uleb128 0x13
.uleb128 0x38
.uleb128 0xb
.byte 0
.byte 0
.uleb128 0xa
.uleb128 0xd
.byte 0
.uleb128 0x3
.uleb128 0xe
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0x5
.uleb128 0x49
.uleb128 0x13
.uleb128 0x38
.uleb128 0xb
.byte 0
.byte 0
.uleb128 0xb
.uleb128 0x16
.byte 0
.uleb128 0x3
.uleb128 0xe
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0xb
.byte 0
.byte 0
.uleb128 0xc
.uleb128 0x1
.byte 0x1
.uleb128 0x49
.uleb128 0x13
.uleb128 0x1
.uleb128 0x13
.byte 0
.byte 0
.uleb128 0xd
.uleb128 0x21
.byte 0
.uleb128 0x49
.uleb128 0x13
.uleb128 0x2f
.uleb128 0xb
.byte 0
.byte 0
.uleb128 0xe
.uleb128 0x13
.byte 0
.uleb128 0x3
.uleb128 0xe
.uleb128 0x3c
.uleb128 0x19
.byte 0
.byte 0
.uleb128 0xf
.uleb128 0x34
.byte 0
.uleb128 0x3
.uleb128 0xe
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0x5
.uleb128 0x49
.uleb128 0x13
.uleb128 0x3f
.uleb128 0x19
.uleb128 0x3c
.uleb128 0x19
.byte 0
.byte 0
.uleb128 0x10
.uleb128 0x34
.byte 0
.uleb128 0x3
.uleb128 0xe
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0xb
.uleb128 0x49
.uleb128 0x13
.uleb128 0x3f
.uleb128 0x19
.uleb128 0x3c
.uleb128 0x19
.byte 0
.byte 0
.uleb128 0x11
.uleb128 0x21
.byte 0
.byte 0
.byte 0
.uleb128 0x12
.uleb128 0x2e
.byte 0x1
.uleb128 0x3f
.uleb128 0x19
.uleb128 0x3
.uleb128 0xe
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0xb
.uleb128 0x49
.uleb128 0x13
.uleb128 0x11
.uleb128 0x1
.uleb128 0x12
.uleb128 0x7
.uleb128 0x40
.uleb128 0x18
.uleb128 0x2116
.uleb128 0x19
.uleb128 0x1
.uleb128 0x13
.byte 0
.byte 0
.uleb128 0x13
.uleb128 0x34
.byte 0
.uleb128 0x3
.uleb128 0x8
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0xb
.uleb128 0x49
.uleb128 0x13
.uleb128 0x2
.uleb128 0x18
.byte 0
.byte 0
.uleb128 0x14
.uleb128 0x1
.byte 0x1
.uleb128 0x49
.uleb128 0x13
.byte 0
.byte 0
.byte 0
.section .debug_aranges,"",@progbits
.long 0x2c
.value 0x2
.long .Ldebug_info0
.byte 0x8
.byte 0
.value 0
.value 0
.quad .Ltext0
.quad .Letext0-.Ltext0
.quad 0
.quad 0
.section .debug_line,"",@progbits
.Ldebug_line0:
.section .debug_str,"MS",@progbits,1
.LASF20:
.string "_IO_buf_end"
.LASF28:
.string "_old_offset"
.LASF52:
.string "sys_nerr"
.LASF23:
.string "_IO_save_end"
.LASF5:
.string "short int"
.LASF7:
.string "size_t"
.LASF10:
.string "sizetype"
.LASF33:
.string "_offset"
.LASF17:
.string "_IO_write_ptr"
.LASF12:
.string "_flags"
.LASF19:
.string "_IO_buf_base"
.LASF24:
.string "_markers"
.LASF14:
.string "_IO_read_end"
.LASF56:
.string "GNU C++14 6.3.0 -masm=intel -mtune=generic -march=x86-64 -g"
.LASF55:
.string "_sys_errlist"
.LASF51:
.string "stderr"
.LASF32:
.string "_lock"
.LASF6:
.string "long int"
.LASF29:
.string "_cur_column"
.LASF48:
.string "_IO_2_1_stderr_"
.LASF60:
.string "_IO_FILE_plus"
.LASF45:
.string "_pos"
.LASF54:
.string "_sys_nerr"
.LASF57:
.string "/tmp/compiler-explorer-compiler117418-65-1oqoejw.mk5ryhkt9/example.cpp"
.LASF44:
.string "_sbuf"
.LASF41:
.string "_IO_FILE"
.LASF1:
.string "unsigned char"
.LASF4:
.string "signed char"
.LASF46:
.string "_IO_2_1_stdin_"
.LASF3:
.string "unsigned int"
.LASF42:
.string "_IO_marker"
.LASF31:
.string "_shortbuf"
.LASF58:
.string "/compiler-explorer"
.LASF16:
.string "_IO_write_base"
.LASF40:
.string "_unused2"
.LASF13:
.string "_IO_read_ptr"
.LASF2:
.string "short unsigned int"
.LASF11:
.string "char"
.LASF61:
.string "main"
.LASF43:
.string "_next"
.LASF34:
.string "__pad1"
.LASF35:
.string "__pad2"
.LASF36:
.string "__pad3"
.LASF37:
.string "__pad4"
.LASF38:
.string "__pad5"
.LASF0:
.string "long unsigned int"
.LASF18:
.string "_IO_write_end"
.LASF9:
.string "__off64_t"
.LASF8:
.string "__off_t"
.LASF25:
.string "_chain"
.LASF22:
.string "_IO_backup_base"
.LASF49:
.string "stdin"
.LASF27:
.string "_flags2"
.LASF39:
.string "_mode"
.LASF15:
.string "_IO_read_base"
.LASF30:
.string "_vtable_offset"
.LASF21:
.string "_IO_save_base"
.LASF53:
.string "sys_errlist"
.LASF26:
.string "_fileno"
.LASF50:
.string "stdout"
.LASF47:
.string "_IO_2_1_stdout_"
.LASF59:
.string "_IO_lock_t"
.ident "GCC: (GCC-Explorer-Build) 6.3.0"
.section .note.GNU-stack,"",@progbits

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote