×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Generate Bingo Cards In MIPS Assembly Language (Using MARS) Assignment Solution

July 03, 2024
Rehana Magnus
Rehana Magnus
🇨🇦 Canada
Assembly Language
Rehana Magnus, PhD in Computer Science from the esteemed Acadia Institute of Technology, Canada. With 6 years of experience, specializes in assembly language programming. Proficient in low-level coding, optimizing performance, and enhancing system functionality.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

Instructions

Objective

Write a MIPS assignment to generate Bingo cards (using MARS).

Requirements and Specifications

In MIPS Assembly Language (Using MARS) do the following: Bingo Card Generator Write a program that will: prompt the user for the number of players (maximum of 2) prompt the user for the number of cards to generate for each player (maximum of 2) for each card for each player, generate a valid bingo card (4 columns and 4 rows) provide a menu for the user to select 1-which user/bingo card to display 2-to run a histogram on the bingo cards generated to see how many times each number between 1 and 75 appeared 3-exit I have a picture attached that will show the desired output. I would need a lot of comments throughout the code. Also as mentioned, programmer has to use MARS to make this program and should be in the format of data and text.

Screenshots of output

program-to-generate-Bingo-cards-in-MIPS-assembly-language
program-to-generate-Bingo-cards-in-MIPS-assembly-language 1
program-to-generate-Bingo-cards-in-MIPS-assembly-language 2
program-to-generate-Bingo-cards-in-MIPS-assembly-language 3

Source Code

.data prompt_np: .asciiz "Please enter number of players: " prompt_nc: .asciiz "Please enter number of cards per player: " menu: .ascii "1. To select user/bingo card to display\n" .ascii "2. To show histogram\n" .asciiz "3. Exit\n" prompt_ch: .asciiz "Please enter your choice: " prompt_pn: .asciiz "Please enter player number (1 - " prompt_cn: .asciiz "Please enter card number (1 - " prompt_end: .asciiz "): " err_nplayers: .asciiz "Invalid number of players. Please try again\n" err_ncards: .asciiz "Invalid number of cards. Please try again\n" err_choice: .asciiz "Invalid choice. Please try again\n" err_player: .asciiz "Invalid player number. Please try again\n" err_card: .asciiz "Invalid card number. Please try again\n" bingo: .asciiz " B I N G O\n" cards: .space 100 # space for a maximum of 2 players * 2 cards * each card of maximum 5*5 numbers histo: .space 75 # space to save histogram .text # Program start main: # read number of players read_nplayers: la $a0, prompt_np # load address of prompt string li $v0, 4 # syscall to print string syscall # print the prompt li $v0, 5 # syscall to read an integer syscall # read the number of players move $s0, $v0 # save number of players blt $v0, 1, bad_nplayers # if not correct, print error ble $v0, 2, read_ncards # if correct, read number of cards bad_nplayers: # print error message la $a0, err_nplayers # load address of error string li $v0, 4 # syscall to print string syscall # print the error message j read_nplayers # try again # read number of cards read_ncards: la $a0, prompt_nc # load address of prompt string li $v0, 4 # syscall to print string syscall # print the prompt li $v0, 5 # syscall to read an integer syscall # read the number of cards move $s1, $v0 # save number of cards blt $v0, 1, bad_ncards # if not correct, print error ble $v0, 2, generate_cards # if correct, generate cards bad_ncards: # print error message la $a0, err_ncards # load address of error string li $v0, 4 # syscall to print string syscall # print the error message j read_ncards # try again generate_cards: # generate cards for all players and fill histogram la $s2, cards # point to start of cards la $s3, histo # point to start of histogram move $t0, $s0 # start with the number of players ploop: move $t1, $s1 # start with the number of cards cloop: li $t2, 24 # start with the number of numbers nloop: li $v0, 42 # syscall to generate a random number in a range li $a0, 0 # generator number 0 li $a1, 75 # generate between 0 and 74 syscall # generate a random number add $t3, $a0, $s3 # add to histo to get position of number lb $t4, 0($t3) # load current count of number addi $t4, $t4, 1 # increment count sb $t4, 0($t3) # save new count addi $a0, $a0, 1 # increment to get a number 1-75 sb $a0, 0($s2) # save in cards addi $s2, $s2, 1 # advance to next space in array addi $t2, $t2, -1 # decrement numbers bnez $t2, nloop # repeat loop while not zero addi $t1, $t1, -1 # decrement cards bnez $t1, cloop # repeat loop while not zero addi $t0, $t0, -1 # decrement players bnez $t0, ploop # repeat loop while not zero # menu loop menu_loop: # print menu la $a0, menu # load address of menu li $v0, 4 # syscall to print string syscall # print the menu options read_choice: # read choice la $a0, prompt_ch # load address of prompt string li $v0, 4 # syscall to print string syscall # print the prompt li $v0, 5 # syscall to read an integer syscall # read the number of players beq $v0, 1, read_player # if 1, display a card, start reading player beq $v0, 2, disp_histo # if 2, display histogram beq $v0, 3, exit # if 3, exit # else, print error message la $a0, err_choice # load address of error string li $v0, 4 # syscall to print string syscall # print the error message j read_choice # try again read_player: # read player number la $a0, prompt_pn # load address of prompt string li $v0, 4 # syscall to print string syscall # print the prompt move $a0, $s0 # load maximum number of players li $v0, 1 # syscall to print a number syscall # print maximum number la $a0, prompt_end # load address of prompt end string li $v0, 4 # syscall to print string syscall # print the prompt end part li $v0, 5 # syscall to read an integer syscall # read the player number move $s2, $v0 # save player number blt $v0, 1, bad_player # if not correct, print error ble $v0, $s0, read_card # if correct, read card bad_player: # print error message la $a0, err_player # load address of error string li $v0, 4 # syscall to print string syscall # print the error message j read_player # try again read_card: # read card number la $a0, prompt_cn # load address of prompt string li $v0, 4 # syscall to print string syscall # print the prompt move $a0, $s1 # load maximum number of cards li $v0, 1 # syscall to print a number syscall # print maximum number la $a0, prompt_end # load address of prompt end string li $v0, 4 # syscall to print string syscall # print the prompt end part li $v0, 5 # syscall to read an integer syscall # read the card number move $s3, $v0 # save card number blt $v0, 1, bad_card # if not correct, print error ble $v0, $s0, display # if correct, print card bad_card: # print error message la $a0, err_card # load address of error string li $v0, 4 # syscall to print string syscall # print the error message j read_card # try again display: la $a0, bingo # load address of bingo string li $v0, 4 # syscall to print string syscall # print the bingo title li $t0, 24 # size of a player entry = 24 * n cards mult $t0, $s1 # multiply 25*number of cards mflo $t0 # load result addi $t1, $s2, -1 # player - 1 mult $t0, $t1 # multiply player size*(player - 1) mflo $t0 # load result li $t1, 24 # size of a card entry = 24 addi $t2, $s3, -1 # card - 1 mult $t1, $t2 # multiply 24*(card - 1) mflo $t1 # load result add $t0, $t0, $t1 # add to get start of card to print la $t1, cards # point to start of cards add $t0, $t0, $t1 # add to base address to get address of card # display all numbers in card li $t1, 5 # start with the number of numbers in row disp_row: li $t2, 5 # start with the number of numbers in col disp_col: bne $t1, 3, skip # if row not 3, display bne $t2, 3, skip # if col not 3, display li $v0, 11 # syscall to print a character li $a0, 32 # load space char syscall # print a space syscall # print double space j next_col # go to next column skip: lb $t3, 0($t0) # load number bge $t3, 10, print # if number > 10, don't print space li $v0, 11 # syscall to print a character li $a0, 32 # load space char syscall # print a space print: li $v0, 1 # syscall to print integer move $a0, $t3 # load number syscall # print the number addi $t0, $t0, 1 # advance to next space in array next_col: li $v0, 11 # syscall to print a character li $a0, 32 # load space char syscall # print a space addi $t2, $t2, -1 # decrement numbers bnez $t2, disp_col # repeat loop while not zero li $v0, 11 # syscall to print a character li $a0, 10 # load newline char syscall # print a newline addi $t1, $t1, -1 # decrement numbers bnez $t1, disp_row # repeat loop while not zero li $v0, 11 # syscall to print a character li $a0, 10 # load newline char syscall # print a newline j menu_loop # repeat loop disp_histo: la $t0, histo # point to start of histogram li $t1, 1 # start in number 1 hist_loop: bge $t1, 10, printnum # if number > 10, don't print space li $v0, 11 # syscall to print a character li $a0, 32 # load space char syscall # print a space printnum: li $v0, 1 # syscall to print integer move $a0, $t1 # load number syscall # print the number li $v0, 11 # syscall to print a character li $a0, ':' # load colon char syscall # print a colon li $v0, 11 # syscall to print a character li $a0, 32 # load space char syscall # print a space lb $t2, 0($t0) # load number from histogram j ast_cmp # jump to comparison ast_loop: li $v0, 11 # syscall to print a character li $a0, '*' # load asterisk char syscall # print an asterisk addi $t2, $t2, -1 # decrement count ast_cmp: bnez $t2, ast_loop # repeat while not zero li $v0, 11 # syscall to print a character li $a0, 10 # load newline char syscall # print a newline addi $t0, $t0, 1 # advance position in histogram addi $t1, $t1, 1 # increment histogram number ble $t1, 75, hist_loop # if num <= 75, print next li $v0, 11 # syscall to print a character li $a0, 10 # load newline char syscall # print a newline j menu_loop # repeat loop exit: li $v0, 10 # syscal to exit program syscall # terminate program

Similar Samples

Discover our array of programming homework samples spanning Java, Python, C++, and more. Each sample exemplifies our proficiency in tackling intricate coding challenges effectively. Whether you're grappling with algorithms, data structures, or software development projects, our samples underscore our dedication to delivering high-quality solutions tailored to your academic needs.