# מבנה המחשב תרגיל 5

קיים מערך נתון , התכנית קולטת מספרים מהמשתמש, ומציבה אותם במערך חדש ובודקת האם המערך שהתקבל מהמשתמש קיים בשלמותו במערך הנתון מראש

התכנית כתובה בשפת אסמבלי

קוד מספר 1

```.data
success: .asciiz "code was found\n"
block1: .byte 1,1,2,3,4,5,6,7,8,9,10,121,12,122,14,15,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
block2: .byte
.text
li \$t6 0               # cin loop 6 times
la \$a1 block1          # poinret to block1
la \$a2 block2          # poinret to block1   (user input)
addi \$sp \$sp -4
sb \$t6 (\$sp)           # save the number of iteation for the print loop

cin:                   # input loop
li \$v0 5
syscall
sb \$v0 (\$a2)           # insert the numner to the block 2 to
addi \$a2 \$a2 1         # promote the pointer
addi \$t6 \$t6 1          # \$t6++
bne \$t6 6 cin      # if \$t6=0 finish
la \$a2 block2          # point to the start of array again

lb \$t6 (\$sp)
addi \$sp \$sp 4

move \$t5 \$0           # initlize
loop:
lb \$t1 (\$a1)          # put the number from block1 in \$t1
lb \$t2 (\$a2)          # put the number from block2 in \$t2
bne \$t1 \$t2 check_again    # if the nembers do not match go to change (to promote th pointer of block1 and rechek)
addi \$a1 \$a1 1        # promote \$a1 to the next number
addi \$a2 \$a2 1        # promote \$a2 to the next number
addi \$t6 \$t6 1         # \$t6--
bne \$t6 6 loop
j found               # go to print found

check_again:
sub \$a1 \$a1 \$t6       #   \$a1=\$a1-\$t6+1
addi \$a1 \$a1 1        #  promote only  \$a1 (pointer of block 1) to the next number
addi \$t5 \$t5 1        # every time that nubers dont match \$t5++
la \$a2 block2         # point to the start of array agine

li \$t6 0              # initilaze the loop counter to 6 again
beq \$t5 27 not_found  # there is no more space to 6 nubers in the block (the 6 numbrs is not in the block)
j loop

found:
li \$v0 4
la \$a0 success
syscall
j print_ok

not_found:
li \$v0 4
la \$a0 not_success
syscall

print_ok:
la \$a2 block2       # point to the start of array again fof printing
li \$t6 6            # initilaze the loop counter to 6 again
print:
lb \$a0 (\$a2)
li \$v0 1
syscall
sub \$t6 \$t6 1
addi \$a2 \$a2 1
bne \$t6 \$0 print

```

התכנית נכתבה ע"י: benny r & david f

קוד מספר 2

```
.data
found: .asciiz "code was found\n"
input_message: .asciiz "password: \n"
block: .byte 9,8,7,6,5,4,3,2,1,1,2,2,1,3,4,5,6,7,8,9,4,4,1,1,2,2,3,3,4,4,5,5
input_block: .byte
.text
la \$s0,input_block  #save the pointer to the beggining of the input_block into \$s0
la \$a0,input_message
li \$v0,4
syscall
li \$t1,6 # down counter for the loop of input (6 numbers)
loop:
blez \$t1, end_input
li \$v0,5
syscall
sb \$v0, (\$s0)
j loop
end_input:

la \$s0,block
la \$s1,input_block
li \$t1,0 #counter for the loop-6
li \$t2,0 #counter for the block-32
loop_check:
beq \$t1, 6, succes
beq \$t2, 27, not_succes
lb \$a0, (\$s0)
lb \$a1, (\$s1)
beq \$a0,\$a1,next_elem
addi \$t2,\$t2,1     #not equle then do block++ and resert the counter to 0
la \$s0,block
add \$s0,\$s0,\$t2    #times we need to block++
la \$s1,input_block
li \$t1,0
j loop_check
next_elem:
j loop_check

#printing result
succes:
la \$a0,found
li \$v0,4
syscall
j end
not_succes:
la \$a0,not_found
li \$v0,4
syscall
end:

```

נכתב ע"י y. levental