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!
\nThe steps are:<\/p>\nA) Send the message: “Enter your registration number”;
\nB) Receive 9 numeric digits corresponding to a registration number;
\nC) If the registration is all zero, and the program (call the system with the exit operation)
\nD) Search in the registrations stored as constants in the program
\nD.1) If you find the registration, present the text:
\n“The registration number XXXXXXXXX corresponds to student YYYYYYYY.”
\nD.2) If you can not find the registration, please submit the text:
\n“Registration XXXXXXXXX was not found”
\nD.3) If the registration number corresponds to your registration number, present the text:
\n“It’s me! I’M YYYYY YYYYY YYYY and my register number is XXXXXXXXX ”
\nE) Go back to step “A”<\/p>\nThe 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
\n12345678h (binary 0001_0010_0011_0100_0101_0110_0111_1000);\n<\/p><\/blockquote>\nSee below:<\/b>
\n
\n# Partially completed solution.
\n.data
\n message: .asciiz \"Enter your registration number: \"
\n found_message: .asciiz \"The registration number XXXXXXXXX corresponds to student YYYYYYYY.\\n\"
\n not_found_message: .asciiz \"Registration XXXXXXXXX was not found.\\n\"
\n my_number_found_message: .asciiz \"It's me! I'M YYYYY YYYYY YYYY, and my register number is XXXXXXXXX.\\n\"
\n registration_names: .asciiz \"XXXXXX\", \"YYYYYY\"
\n registration_numbers: .word 0x0000000, 0x000000
\n my_number: .word 0x000000<\/p>\n.eqv ARRAY_SIZE 8 # 2 ints = 8 bytes
\n.text
\n main:
\n loop:
\n # Show prompt.
\n li $v0, 4
\n la $a0, message
\n syscall<\/p>\n# Get input.
\n li $v0, 5
\n syscall<\/p>\n# If all 0's, then end program.
\n move $a0, $v0
\n beqz $a0, main_exit<\/p>\n# Search (pass value to search in $a1).
\n move $a1, $a0
\n jal search_registration <\/p>\nb loop <\/p>\n
main_exit:
\n li $v0, 10
\n syscall<\/p>\n# Expects user input in $a1.
\n search_registration:
\n # $t1 is loop index. $t2 is my number.
\n li $t1, 0
\n search_loop:
\n lw $a0, registration_numbers($t1)
\n beq, $a0, $a1, number_found
\n addi $t1, $t1, 4
\n beq $t1, ARRAY_SIZE, number_not_found
\n blt $t1, ARRAY_SIZE, search_loop<\/p>\nnumber_found:
\n lw $t2, my_number
\n beq $a0, $t2, my_number_found
\n li $v0, 4
\n la $a0, found_message
\n syscall <\/p>\nb search_registration_exit
\n my_number_found:
\n li $v0, 4
\n la $a0, my_number_found_message<\/p>\nsyscall
\n b search_registration_exit
\n number_not_found:
\n li $v0, 4
\n la $a0, not_found_message
\n syscall
\n search_registration_exit:
\n jr $ra<\/p>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"
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 […]<\/p>\n","protected":false},"author":1,"featured_media":1098,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,26,7],"tags":[],"jetpack_featured_media_url":"https:\/\/smartvania.com\/wp-content\/uploads\/2016\/03\/LTSK-copy.png","_links":{"self":[{"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/posts\/1554"}],"collection":[{"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/comments?post=1554"}],"version-history":[{"count":4,"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/posts\/1554\/revisions"}],"predecessor-version":[{"id":1558,"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/posts\/1554\/revisions\/1558"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/media\/1098"}],"wp:attachment":[{"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/media?parent=1554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/categories?post=1554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartvania.com\/wp-json\/wp\/v2\/tags?post=1554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}