Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

CSC 311: COMPUTER ORGANIZATION AND ARCHITECTURE Lab 7 – Due 04/07/2022, 11:59 PM This lab provides experience with dynamic memory allocation and strings. Write a program that applies run length...

1 answer below »



CSC 311: COMPUTER ORGANIZATION AND ARCHITECTURE

Lab 7 – Due 04/07/2022, 11:59 PM

This lab provides experience with dynamic memory allocation and strings.

Write a program that applies run length encoding compression to a given string. Follow the below steps:

1. Dynamically allocate memory from heap for two strings (an input string and an output string).
2. Read an input string (a-z, A-Z) of size less than 40 characters in this dynamic memory.
3. Iterate over the string looking for consecutive occu
ences of the same character and replace
them with the character and a count.
4. Example, if the input string is AAAAAA, the output string should be A6. If you see
BBCCCCCCCCCCCCC, the output should be B2C13.
5. Note that the number 13 is represented as two separate characters ‘1’ and ‘3’ in the output string.
6. Single character occu
ences do not need a count.
7. The output string should also be stored in the dynamic memory before it is displayed on the
console.
8. Implement a loop back to the main function. See the prompts below:
“Enter a string:”
“Compressed string is:”
“Do you want to apply run length encoding again?”

9. Test the program using the following data:
a. Input: AAAAaaa
cde Compressed string: A4a3b2cde
. Input: XXXXXXXXXXYYZZZWERTT Compressed string: X10Y2Z3WERT2


Submission guidelines:

You need to submit your Lab7.asm file and a screenshot of the Run/IO display with input values:

1) AAAAAAAAAAAA
OOOPPPPP
2) LLKKKJHGSSDDDDD

Submit a single .zip file with name Lab7_firstname_lastname.zip (Your .zip file should contain
Lab7.asm and Screenshot).

1
Chapter 8: Dynamic Memory
Allocation and Strings
CSC311 Computer Organization and
Architecture
Adita Kulkarni
Overview
 Memory
 Heap
 Syscalls
 8, 9, 11
 Instructions
 lb, s
 Convert integer to character – ‘0’
2
Memory Layout
 Heap
 Dynamic memory allocation
3
System Services
 A small set of operating system-like services through the
system call (syscall) instruction
4
Code
5
 Allocate Memory
li $v0, 9 #syscall for dynamic memory allocation (s
k)
li $a0, 80
syscall
move $s0, $v0
 Read String into the dynamically allocated memory
li $v0, 8 #syscall read string
la $a0, 0($s0) #buffe
li $a1, 40 #length
syscall
Instructions
6
 Size
 Integer – 4 bytes
 Character – 1 byte
 Instructions
 lb $t1, 0($t0)
 sb $t1, 0($s0)
Example: Copy string character by characte
7
.data # Data declaration section
Prompt1: .asciiz "\n Enter a string:"
.text
main:
li $v0, 4 #Prints String
la $a0, Prompt1
syscall
li $v0, 9
li $a0, 80
syscall
move $s0, $v0
li $v0, 8
la $a0, 0($s0)
li $a1, 30
syscall
move $t0, $a0
li $t4, 0
Loop:
lb $t1, 0($t0)
sb $t1, 40($s0)
addi $t0, $t0, 1
addi $t4, $t4, 1
addi $s0, $s0, 1
eq $t1, 0, End
j Loop
End:
neg $t4, $t4
add $s0, $s0, $t4
li $v0,4
la $a0, 40($s0)
syscall
#Exit
Convert Integer to Characte
8
 Add '0'
 Compiler understands '0' as 48
 Example
 li $t3, 1
 add $t4, $t3, '0'
    Slide Number 1
    Overview
    Memory Layout
    System Services
    Code
    Instructions
    Example: Copy string character by characte
    Convert Integer to Characte
Answered Same Day Apr 08, 2022

Solution

Gaurav answered on Apr 09 2022
106 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here