Warning: Undefined array key "hide_archive_titles" in /home1/smartva9/public_html/smartvania/wp-content/themes/baton/includes/theme-functions.php on line 254

Category: Assembly

Code Request

I was watching your videos on youtube about assembly, but I have many doubts… I have an exercise to do until next Sunday, and I don’t know how to do it!
The steps are:

A) Send the message: “Enter your registration number”;
B) Receive 9 numeric digits corresponding to a registration number;
C) If the registration is all zero, and the program (call the system with the exit operation)
D) Search in the registrations stored as constants in the program
D.1) If you find the registration, present the text:
“The registration number XXXXXXXXX corresponds to student YYYYYYYY.”
D.2) If you can not find the registration, please submit the text:
“Registration XXXXXXXXX was not found”
D.3) If the registration number corresponds to your registration number, present the text:
“It’s me! I’M YYYYY YYYYY YYYY and my register number is XXXXXXXXX ”
E) Go back to step “A”

The names must be stored using .asciiz and the registration numbers must be stored as a 32-bit integer, formatted as BCD, that is, every 4 bits, we have a decimal digit. The first number of the register number is always 1 and should not be stored. Registration example: 112345678 will be stored in hexadecimal as
12345678h (binary 0001_0010_0011_0100_0101_0110_0111_1000);

See below:

# Partially completed solution.
.data
message: .asciiz "Enter your registration number: "
found_message: .asciiz "The registration number XXXXXXXXX corresponds to student YYYYYYYY.\n"
not_found_message: .asciiz "Registration XXXXXXXXX was not found.\n"
my_number_found_message: .asciiz "It's me! I'M YYYYY YYYYY YYYY, and my register number is XXXXXXXXX.\n"
registration_names: .asciiz "XXXXXX", "YYYYYY"
registration_numbers: .word 0x0000000, 0x000000
my_number: .word 0x000000

.eqv ARRAY_SIZE 8 # 2 ints = 8 bytes
.text
main:
loop:
# Show prompt.
li $v0, 4
la $a0, message
syscall

# Get input.
li $v0, 5
syscall

# If all 0's, then end program.
move $a0, $v0
beqz $a0, main_exit

# Search (pass value to search in $a1).
move $a1, $a0
jal search_registration

b loop

main_exit:
li $v0, 10
syscall

# Expects user input in $a1.
search_registration:
# $t1 is loop index. $t2 is my number.
li $t1, 0
search_loop:
lw $a0, registration_numbers($t1)
beq, $a0, $a1, number_found
addi $t1, $t1, 4
beq $t1, ARRAY_SIZE, number_not_found
blt $t1, ARRAY_SIZE, search_loop

number_found:
lw $t2, my_number
beq $a0, $t2, my_number_found
li $v0, 4
la $a0, found_message
syscall

b search_registration_exit
my_number_found:
li $v0, 4
la $a0, my_number_found_message

syscall
b search_registration_exit
number_not_found:
li $v0, 4
la $a0, not_found_message
syscall
search_registration_exit:
jr $ra

2D Arrays (MIPS) a brief explanation


Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Cookie/Jar.php on line 63

Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Cookie/Jar.php on line 73

Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Cookie/Jar.php on line 89

Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Cookie/Jar.php on line 102

Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Cookie/Jar.php on line 111

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/smartva9/public_html/smartvania/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91

Introduction to MIPS

This tutorial will get you up and running with the great MIPS instruction set. MIPS stands for Microprocessor without Interlocked Pipeline Stages, and it is a Reduced Instruction Set Computer assembly language. That means that the creators of MIPS designed it to be reduced or simplified, which is the reason that many universities around the world teach MIPS as a first assembly language.

In this tutorial I will try to be concise, clear and helpful. Whether you are going to take a course in college and want to prepare for it, or you are a self learner, a computer enthusiast, a veteran programmer or anybody who wants to learn assembly language the easy way, or brush up on it, then this tutorial series is for you. Enjoy!