# Assembly Homework Help, Project Help, Assembly Assignment Solution

The personal computer we use have a microprocessor that manages the computer’s arithmetical, logical and control activities. Assembly language uses machine language instruction that students learn in their semesters. They have to complete several assignment questions along with the projects.

This is the first site to come to for solutions to your Assembly problems. If you are looking for help on Assembly then, I’m not aware of anywhere else where you can get better service.

Since I already showed a Java Sudoku solver, here is one in Assembly language. It is a lot more complex, and does not allow you to enter a board, it just attempts to solve one. There are multiple assembly languages, this one is Mips and runs on the Mars simulator.

This is a moderately complex board, that the program can solve.

```Welcome to Sudoku Solver
This program solves Sudoku Puzzles or checks for validity
+---+---+---+
|53 | 7 |   |
|6  |195|   |
| 98|   | 6 |
+---+---+---+
|8  | 6 |  3|
|4  |8 3|  1|
|7  | 2 |  6|
+---+---+---+
| 6 |   |28 |
|   |419|  5|
|   | 8 | 79|
+---+---+---+
Attempting to solve puzzle
+---+---+---+
|53 | 7 |   |
|6  |195|   |
| 98|   | 6 |
+---+---+---+
|8  | 6 |  3|
|4  |853|  1|
|7  |92 |  6|
+---+---+---+
| 6 | 37|284|
|   |419| 35|
|   | 8 | 79|
+---+---+---+
Attempting to solve puzzle
+---+---+---+
|53 | 7 |   |
|6  |195|   |
| 98| 42| 67|
+---+---+---+
|8  |76 |  3|
|42 |853| 91|
|7  |92 |  6|
+---+---+---+
| 6 |537|284|
|2 7|419|635|
|   | 86|179|
+---+---+---+
Attempting to solve puzzle
+---+---+---+
|53 |678|  2|
|6  |195| 48|
|198|342|567|
+---+---+---+
|8  |76 |4 3|
|426|853|791|
|7  |92 |856|
+---+---+---+
|961|537|284|
|287|419|635|
|3  |286|179|
+---+---+---+
Attempting to solve puzzle
+---+---+---+
|534|678|912|
|672|195|348|
|198|342|567|
+---+---+---+
|8  |761|423|
|426|853|791|
|713|924|856|
+---+---+---+
|961|537|284|
|287|419|635|
|3 5|286|179|
+---+---+---+
Attempting to solve puzzle
+---+---+---+
|534|678|912|
|672|195|348|
|198|342|567|
+---+---+---+
|859|761|423|
|426|853|791|
|713|924|856|
+---+---+---+
|961|537|284|
|287|419|635|
|345|286|179|
+---+---+---+
Attempting to solve puzzle
+---+---+---+
|534|678|912|
|672|195|348|
|198|342|567|
+---+---+---+
|859|761|423|
|426|853|791|
|713|924|856|
+---+---+---+
|961|537|284|
|287|419|635|
|345|286|179|
+---+---+---+
Goodbye```

And this is a board where it is invalid.

```Welcome to Sudoku Solver
This program solves Sudoku Puzzles or checks for validity
+---+---+---+
|337|964|281|
|468|123|579|
|912|587|463|
+---+---+---+
|631|795|842|
|724|318|695|
|895|226|137|
+---+---+---+
|176|459|328|
|583|672|914|
|249|831|756|
+---+---+---+
row 6 has 2 2's
column 5 has 2 2's
block 5 has 2 2's
column 2 has 2 3's
row 1 has 2 3's
block 1 has 2 3's
Unable to solve a board, due to the fact it has errors
Goodbye```

Our experts who offer assembly language homework help to the students discuss about the family of processors which has its own set of instructions for handling various operations such as getting input from keyboard, displaying information on screen and performing various other jobs. These set of instructions are known as machine language instruction.

I’ll include the full code here and then discuss it after the listing.

## sudoku-mips.asm

```.macro print_int (%x)
li \$v0, 1
syscall
.end_macro

.macro push (%x)
sw %x, (\$sp)
subi \$sp, \$sp, 4
.end_macro

.macro pop (%x)
lw %x, (\$sp)
.end_macro

.macro call (%r)
push \$ra
jal %r
pop \$ra
.end_macro

.data

welcome: .asciiz "Welcome to Sudoku Solver\nThis program solves Sudoku Puzzles or checks for validity\n"
bye:    .asciiz "Goodbye\n"
unable_error: .asciiz "Unable to solve a board, due to the fact it has errors\n"
nothing_to_do: .asciiz "Nothing to solve, the board is already complete\n"
attempting: .asciiz "Attempting to solve puzzle\n"

sudokuboard:
.asciiz "337964281468123579912587463631795842724318695895226137176459328583672914249831756" #Invalid
#   .asciiz "357964281468123579912587463631795842724318695895246137176459328583672914249831756" #Complete
#   .asciiz "3579642e14681235e991258746363179584272431869e895246e3717645932e583672914249e31756" #Easy
#   .asciiz "53ee7eeee6ee195eeee98eeee6e8eee6eee34ee8e3ee17eee2eee6e6eeee28eeee419ee5eeee8ee79"

row:    .asciiz "row "
column: .asciiz "column "
block:  .asciiz "block "
has:    .asciiz " has "
endline:    .asciiz "\n"
space:  .asciiz " "
apos:   .asciiz "'s "

board:  .ascii "???"
board2: .ascii "???"
board3: .ascii "???      \n"
.ascii "?????????      \n"
.ascii "?????????      \n"
board4: .ascii "???"
board5: .ascii "???"
board6: .ascii "???      \n"
.ascii "?????????      \n"
.ascii "?????????      \n"
board7: .ascii "???"
board8: .ascii "???"
board9: .ascii "???      \n"
.ascii "?????????      \n"
.asciiz "?????????      \n"

boardline:  .asciiz "|???|???|???|\n"
seperator:  .asciiz "+---+---+---+\n"

blocks: .word board, board2, board3
.word board4, board5, board6
.word board7, board8, board9

solved: .byte 1
errors: .byte 0
changed:.byte 0

offsets:.byte 1, 1, 14, 1, 1, 14, 1, 1, 14      #offset to next square in block

#which row, column, block does each square belong to?
solve:
.byte 0 , 0 , 0 , 0 , 1 , 0 , 0 , 2 , 0 , 0 , 3 , 1 , 0 , 4 , 1 , 0 , 5 , 1 , 0 , 6 , 2 , 0 , 7 , 2 , 0 , 8 , 2
.byte 1 , 0 , 0 , 1 , 1 , 0 , 1 , 2 , 0 , 1 , 3 , 1 , 1 , 4 , 1 , 1 , 5 , 1 , 1 , 6 , 2 , 1 , 7 , 2 , 1 , 8 , 2
.byte 2 , 0 , 0 , 2 , 1 , 0 , 2 , 2 , 0 , 2 , 3 , 1 , 2 , 4 , 1 , 2 , 5 , 1 , 2 , 6 , 2 , 2 , 7 , 2 , 2 , 8 , 2
.byte 3 , 0 , 3 , 3 , 1 , 3 , 3 , 2 , 3 , 3 , 3 , 4 , 3 , 4 , 4 , 3 , 5 , 4 , 3 , 6 , 5 , 3 , 7 , 5 , 3 , 8 , 5
.byte 4 , 0 , 3 , 4 , 1 , 3 , 4 , 2 , 3 , 4 , 3 , 4 , 4 , 4 , 4 , 4 , 5 , 4 , 4 , 6 , 5 , 4 , 7 , 5 , 4 , 8 , 5
.byte 5 , 0 , 3 , 5 , 1 ,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12 3   4       5               "
.ascii "6                               "
.ascii "7                               "
.ascii "                                "
.ascii "8                               "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "9                               "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "                                "

.align 2
counts: .space 12
possible:
.space  640     #16 ints per line, * 10 lines
.text
main:
la  \$a0, welcome
li      \$v0, 4
syscall         #display welcome message

la  \$a0, sudokuboard
jal copyboard
jal displayBoard    #display the initial board
jal validBoard

la  \$t0, errors #check for errors
lb  \$t0, (\$t0)
beq \$t0, \$zero, no_errors
la  \$a0, unable_error
li  \$v0, 4
j   finish
no_errors:
la  \$t0, solved #check if it is solved
lb  \$t0, (\$t0)
beq \$t0, \$zero, trysolve
la  \$a0, nothing_to_do
li  \$v0, 4
j   finish
trysolve:la \$a0, attempting
li  \$v0, 4
jal attempt
jal displayBoard
la  \$a0, changed
lb  \$a0, (\$a0)
bne \$a0, \$zero, trysolve
finish:
la  \$a0, bye
li      \$v0, 4
syscall         #display welcome message
li  \$v0, 10
syscall         #exit

copyboard:
#\$a0 is address of the board
li  \$t1, 81     #81 tiles in the board
li  \$t2, 'e'    #the empty square marker
la  \$t4, solved #have we solved it? (if there are no e then it is complete, unless there are errors)
clrE:
lb  \$t3, (\$a0)
bne \$t3, \$t2, notE  #Not an e, so we don't need to replace it
li  \$t3, ' '
sb  \$t3, (\$a0)
sb  \$zero, (\$t4)
notE:   addi    \$a0, \$a0, 1 #Next position in the board
subi    \$t1, \$t1, 1
bne \$t1, \$0, clrE
subi    \$a0, \$a0, 81
la  \$a1, board
li  \$t1, 9
copyboard1:         #Now we copy the entire board
lb  \$t0, (\$a0)  #Copy a vertical column
sb  \$t0, (\$a1)
lb  \$t0, 9(\$a0)
sb  \$t0, 16(\$a1)
lb  \$t0, 18(\$a0)
sb  \$t0, 32(\$a1)
lb  \$t0, 27(\$a0)
sb  \$t0, 48(\$a1)
lb  \$t0, 36(\$a0)
sb  \$t0, 64(\$a1)
lb  \$t0, 45(\$a0)
sb  \$t0, 80(\$a1)
lb  \$t0, 54(\$a0)
sb  \$t0, 96(\$a1)
lb  \$t0, 63(\$a0)
sb  \$t0, 112(\$a1)
lb  \$t0, 72(\$a0)
sb  \$t0, 128(\$a1)
subi    \$t1, \$t1, 1 #One less to column to do
bne \$t1, \$0, copyboard1
jr  \$ra

#Display the board, uses seperators to make it display better
displayBoard:
la  \$a0, seperator  #+---+---+---+
li  \$v0, 4
syscall
move    \$a3, \$a0
la  \$a0, boardline  #|???|???|???|
move    \$a2, \$a0
la  \$a1, board
li  \$t0, 3
li  \$t1, 3
displayBoard1:          #copy over the ?
lb  \$t2, (\$a1)
sb  \$t2, 1(\$a0)
lb  \$t2, 1(\$a1)
sb  \$t2, 2(\$a0)
lb  \$t2, 2(\$a1)
sb  \$t2, 3(\$a0)

lb  \$t2, 3(\$a1)
sb  \$t2, 5(\$a0)
lb  \$t2, 4(\$a1)
sb  \$t2, 6(\$a0)
lb  \$t2, 5(\$a1)
sb  \$t2, 7(\$a0)

lb  \$t2, 6(\$a1)
sb  \$t2, 9(\$a0)
lb  \$t2, 7(\$a1)
sb  \$t2, 10(\$a0)
lb  \$t2, 8(\$a1)
sb  \$t2, 11(\$a0)    #display the line
syscall
addi    \$a1, \$a1, 16    #move onto the next line
subi    \$t1, \$t1, 1
bne \$t1, \$zero, displayBoard1
li  \$t1, 3
move    \$a0, \$a3    #display the seperator
syscall
move    \$a0, \$a2    #restore the boardline
subi    \$t0, \$t0, 1
bne \$t0, \$zero, displayBoard1
jr  \$ra

validBoard:
#Check for multiple copies of a digit, in a row, column, or block
push    \$ra
la  \$a1, board
li  \$s0, 8      #column, row, and block to check
li  \$s1, '1'    #subtract form each to get bit
la  \$s2, counts #count how many occurences
li  \$s3, 2      #it will equal 2 at some point if there is an error
validBoard1:
jal checkHorizontal #check row
beq \$v0, \$zero, validBoard2 #no error found
la  \$a0, row    #error was in the row
jal validError  #display the error message
validBoard2:
jal checkVertical   #check column
beq \$v0, \$zero, validBoard3 #no error found
la  \$a0, column #display column message
jal validError
validBoard3:
jal checkBlock  #check for problems in a 3x3 block area
beq \$v0, \$zero, validBoard4 #no errors found
la  \$a0, block
jal validError
validBoard4:
subi    \$s0, \$s0, 1 #now check the previous row,column,block
bge \$s0, \$zero, validBoard1 #we still have some left to check
jr  \$ra

validError:
#\$a0 = "row ", "column ", "block "
#\$a1 = row#, column#, block#
li      \$v0, 4
syscall             #print
li  \$v0, 1
la  \$a0, errors
sb  \$v0, (\$a0)
print_int \$s4
la  \$a0, has
li      \$v0, 4
syscall             #print "has "
move    \$t0, \$s2
li  \$t1, 1
li  \$t2, 9
errorLoop:
lb  \$t3, (\$t0)      #get count
bgt \$s3, \$t3, notError
print_int \$t3
la  \$a0, space
li  \$v0, 4
syscall             #print space
print_int \$t1
la  \$a0, apos
li  \$v0, 4
syscall             #print 's
notError:
subi    \$t2, \$t2, 1
bne \$t2, \$zero, errorLoop
la  \$a0, endline
li      \$v0, 4
syscall             #print cr,lf
jr  \$ra

checkHorizontal:
#\$a1 = board
#\$s0 = row
#\$s1 = '1' (to subtract)
#\$s2 = counts
#\$s3 = 2 (for count error)
sw  \$zero, (\$s2)        #clear counts
sw  \$zero, 4(\$s2)
sw  \$zero, 8(\$s2)
sll \$t0, \$s0, 4     #multiply by 16
li  \$t1, 9
move    \$v0, \$zero      #no error
checkHorizontal1:
lb  \$t2, (\$t0)
sub \$t2, \$t2, \$s1
blt \$t2, \$zero, checkHorizontal2    #space, so can't be error
add \$t3, \$s2, \$t2       #get the digit
lb  \$t4, (\$t3)
addi    \$t4, \$t4, 1     #increment the count
sb  \$t4, (\$t3)
bne \$t4, \$s3, checkHorizontal2  #count not equal to 2
li  \$v0, 1          #an error occured
checkHorizontal2:
subi    \$t1, \$t1, 1
bne \$t1, \$zero, checkHorizontal1
jr  \$ra         #return

checkVertical:
#\$a1 = board
#\$s0 = column
#\$s1 = '1' (to subtract)
#\$s2 = counts
#\$s3 = 2 (for count error)
sw  \$zero, (\$s2)        #clear counts
sw  \$zero, 4(\$s2)
sw  \$zero, 8(\$s2)
li  \$t1, 9
move    \$v0, \$zero
checkVertical1:
lb  \$t2, (\$t0)
sub \$t2, \$t2, \$s1
blt \$t2, \$zero, checkVertical2  #space
add \$t3, \$s2, \$t2       #get the digit
lb  \$t4, (\$t3)
sb  \$t4, (\$t3)
bne \$t4, \$s3, checkVertical2    #count did not reach 2
li  \$v0, 1          #an error occured
checkVertical2:
subi    \$t1, \$t1, 1
bne \$t1, \$zero, checkVertical1
jr  \$ra         #return

checkBlock:
#\$a1 = board
#\$s0 = block
#\$s1 = '1' (to subtract)
#\$s2 = counts
#\$s3 = 2 (for count error)
sw  \$zero, (\$s2)        #clear counts
sw  \$zero, 4(\$s2)
sw  \$zero, 8(\$s2)
la  \$t0, blocks
sll \$t1, \$s0, 2     #multiply by 4
lw  \$t0, (\$t0)      #get the address of the block

la  \$t5, offsets        #offset to the next tile in the block
li  \$t1, 9
move    \$v0, \$zero      #no error
checkBlock1:
lb  \$t2, (\$t0)
sub \$t2, \$t2, \$s1
blt \$t2, \$zero, checkBlock2 #space means we don't need to check
lb  \$t4, (\$t3)
sb  \$t4, (\$t3)
bne \$t4, \$s3, checkBlock2
li  \$v0, 1          #an error occured
checkBlock2:
lb  \$t6, (\$t5)      #get the next offset
add \$t0, \$t0, \$t6       #update the position
subi    \$t1, \$t1, 1
bne \$t1, \$zero, checkBlock1
jr  \$ra         #return

testHorizontal:
#\$a1 = board
#\$s0 = row
#\$s1 = '1' (to subtract)
#\$s3 = 1 (for shift)
sll \$t0, \$s0, 4     #multiply by 16
li  \$t1, 9
testHorizontal1:
lb  \$t2, (\$t0)
sub \$t2, \$t2, \$s1
blt \$t2, \$zero, testHorizontal2 #space means ignore
sllv    \$t3, \$s3, \$t2       #set bit mask
or  \$v0, \$v0, \$t3
testHorizontal2:
subi    \$t1, \$t1, 1
bne \$t1, \$zero, testHorizontal1
jr  \$ra         #return

testVertical:
#\$a1 = board
#\$s0 = column
#\$s1 = '1' (to subtract)
#\$s3 = 1 (for shift)
li  \$t1, 9
testVertical1:
lb  \$t2, (\$t0)
sub \$t2, \$t2, \$s1
blt \$t2, \$zero, testVertical2   #space means ignore
sllv    \$t3, \$s3, \$t2       #set bit mask
or  \$v0, \$v0, \$t3
testVertical2:
addi    \$t0, \$t0, 16        #next line
subi    \$t1, \$t1, 1
bne \$t1, \$zero, testVertical1
jr  \$ra         #return

testBlock:
#\$a1 = board
#\$s0 = row
#\$s1 = '1' (to subtract)
#\$s3 = 1 (for shift)
la  \$t0, blocks
sll \$t1, \$s0, 2     #multiply by 4
lw  \$t0, (\$t0)      #get the address of the block

la  \$t5, offsets
li  \$t1, 9
testBlock1:
lb  \$t2, (\$t0)
sub \$t2, \$t2, \$s1
blt \$t2, \$zero, testBlock2  #space ignore
sllv    \$t3, \$s3, \$t2       #get bit mask
or  \$v0, \$v0, \$t3
testBlock2:
lb  \$t6, (\$t5)      #next offset position
subi    \$t1, \$t1, 1
bne \$t1, \$zero, testBlock1
jr  \$ra         #return

attempt:
#make an attempt to solve
push    \$ra         #we will call routines, so save the return address
la  \$t9, changed        #did we make any changes
sb  \$zero, (\$t9)        #say no for now
la  \$a1, board      #the tiles
la  \$a2, solve      #the board layout (row, column, block for each element)
la  \$a3, possible       #possible values
li  \$s1, '1'        #subtract to get base
li  \$s3, 1
li  \$s2, 81         #81 tiles to check
li  \$s4, ' '
li  \$s6, 511        #9 bits all set
la  \$s7, bitstodigit
attempt1:
move    \$v0, \$zero      #which bits are set
lb  \$s0, 0(\$a2)
sll \$t0, \$s0, 4
jal testHorizontal      #check row
lb  \$s0, 1(\$a2)
add \$s5, \$s5, \$s0       #board position
lb  \$t0, (\$s5)
bne \$t0, \$s4, attempt2  #already got a value, so no point calculating
jal testVertical        #check column
lb  \$s0, 2(\$a2)
jal testBlock       #and check the block
xor \$v0, \$v0, \$s6       #we set, so now we invert (so only possible values remain)
sw  \$v0, (\$a3)      #store in the possible array
lb  \$v0, (\$v0)
sb  \$v0, (\$s5)      #update the board
beq \$v0, \$s4, attempt2  #if it was not a space
sb  \$s3, (\$t9)      #changed = 1
attempt2:
addi    \$a2, \$a2, 3     #update the solve
addi    \$a3, \$a3, 4     #the possible
subi    \$s2, \$s2, 1     #and the number of tiles
bne \$zero, \$s2, attempt1    #more tiles to process

pop \$ra         #restore the return address
jr  \$ra```

### Macros

```.macro print_int (%x)
li \$v0, 1
syscall
.end_macro

.macro push (%x)
sw %x, (\$sp)
subi \$sp, \$sp, 4
.end_macro

.macro pop (%x)
lw %x, (\$sp)
.end_macro

.macro call (%r)
push \$ra
jal %r
pop \$ra
.end_macro```

A macro allows you to group a series of instructions together, it’s sort of a function but rather than the function, the instructions that make up the macro appear in the place where it is called.

The macro print_int calls the system function, which needs the value 1 in \$v0 and the value is \$a0. So we add 0 to the register we want to display, and store the result in \$a0, then call the system.

The push macro, pushes a register to the stack, and modifies the stack, and the pop macro does the reverse. The call macro is for calling routines (it saves the state of \$ra).

Students visit our website programming homework help in search of assembly language assignment questions to get the solutions and understand the concept behind it. Learners find our assembly language assignment help very useful as they get the support from our experts with solutions. The assembly language projects for students are very important in their semester examinations. Our tutors have found the learners are in need of help with assembly language project for proper guidance from our experts.

### String Data

```welcome: .asciiz "Welcome to Sudoku Solver\nThis program solves Sudoku Puzzles or checks for validity\n"
bye:    .asciiz "Goodbye\n"
unable_error: .asciiz "Unable to solve a board, due to the fact it has errors\n"
nothing_to_do: .asciiz "Nothing to solve, the board is already complete\n"
attempting: .asciiz "Attempting to solve puzzle\n"

sudokuboard:
.asciiz "337964281468123579912587463631795842724318695895226137176459328583672914249831756" #Invalid
#   .asciiz "357964281468123579912587463631795842724318695895246137176459328583672914249831756" #Complete
#   .asciiz "3579642e14681235e991258746363179584272431869e895246e3717645932e583672914249e31756" #Easy
#   .asciiz "53ee7eeee6ee195eeee98eeee6e8eee6eee34ee8e3ee17eee2eee6e6eeee28eeee419ee5eeee8ee79"

row:    .asciiz "row "
column: .asciiz "column "
block:  .asciiz "block "
has:    .asciiz " has "
endline:    .asciiz "\n"
space:  .asciiz " "
apos:   .asciiz "'s "

board:  .ascii "???"
board2: .ascii "???"
board3: .ascii "???      \n"
.ascii "?????????      \n"
.ascii "?????????      \n"
board4: .ascii "???"
board5: .ascii "???"
board6: .ascii "???      \n"
.ascii "?????????      \n"
.ascii "?????????      \n"
board7: .ascii "???"
board8: .ascii "???"
board9: .ascii "???      \n"
.ascii "?????????      \n"
.asciiz "?????????      \n"

boardline:  .asciiz "|???|???|???|\n"
seperator:  .asciiz "+---+---+---+\n"```

To print a message we need to have a string constant, so that accounts for a lot of these. boardline and seperator are used to print out the screen. sudokuboard gives the puzzle we are attempting to solve, there are 4 examples, the first is an invalid board (not possible due to errors), the second is an already completed board, the third is an easy one with only a few squares left to fill in, and the last is moderately difficult puzzle. The board is laid out so that it can easily checked in the row, column and block, and is copied for displaying. It is in 16 characters per line with spaces at the end so that we can use shifts to access any row (row << 4 gives index for row). The board line and board separator are used to display the puzzle.

Beginners always seek help from our assembly language experts for their assembly language projects. The main internal hardware of a PC that consists of the processor, memory and the registers. Students usually have to solve several assignment problems related to registers. The registers are processor components, holding data and address and to execute a program the system copies it from the external device into the internal memory. Learners generally have confusion in the three sections, which is the data, bss and text section in assembly program.

### Data

```blocks: .word board, board2, board3
.word board4, board5, board6
.word board7, board8, board9

solved: .byte 1
errors: .byte 0
changed:.byte 0

offsets:.byte 1, 1, 14, 1, 1, 14, 1, 1, 14      #offset to next square in block

#which row, column, block does each square belong to?
solve:
.byte 0 , 0 , 0 , 0 , 1 , 0 , 0 , 2 , 0 , 0 , 3 , 1 , 0 , 4 , 1 , 0 , 5 , 1 , 0 , 6 , 2 , 0 , 7 , 2 , 0 , 8 , 2
.byte 1 , 0 , 0 , 1 , 1 , 0 , 1 , 2 , 0 , 1 , 3 , 1 , 1 , 4 , 1 , 1 , 5 , 1 , 1 , 6 , 2 , 1 , 7 , 2 , 1 , 8 , 2
.byte 2 , 0 ,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 6, 4, 5, 5, 6, 5, 6, 6, 7,
.byte 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
.byte 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
.byte 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, 5, 6, 6, 7, 6, 7, 7, 8, 6, 7, 7, 8, 7, 8, 8, 9,
bitstodigit:
.ascii " 12 3   4       5               "
.ascii "6                               "
.ascii "7                               "
.ascii "                                "
.ascii "8                               "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "9                               "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "                                "
.ascii "                                "

.align 2
counts: .space 12
possible:
.space  640     #16 ints per line, * 10 lines```

blocks is used to get the address of where each block starts, offsets is used to add to the current position to get to the next one, solve is used to convert an index into the row / column / block (this could be done with modulo and divisions, but easier in a table). bitcount is used when constructing masks and was generated via an external program. bitstodigit is used when a bit pattern represents a single digit. counts is used to keep track of how often each digit occurs (for error checking), and possible is where the board is calculated.

### main:

```main:
la  \$a0, welcome
li      \$v0, 4
syscall         #display welcome message

la  \$a0, sudokuboard
jal copyboard
jal displayBoard    #display the initial board
jal validBoard

la  \$t0, errors #check for errors
lb  \$t0, (\$t0)
beq \$t0, \$zero, no_errors
la  \$a0, unable_error
li  \$v0, 4
j   finish
no_errors:
la  \$t0, solved #check if it is solved
lb  \$t0, (\$t0)
beq \$t0, \$zero, trysolve
la  \$a0, nothing_to_do
li  \$v0, 4
j   finish
trysolve:la \$a0, attempting
li  \$v0, 4
jal attempt
jal displayBoard
la  \$a0, changed
lb  \$a0, (\$a0)
bne \$a0, \$zero, trysolve
finish:
la  \$a0, bye
li      \$v0, 4
syscall         #display welcome message
li  \$v0, 10
syscall         #exit```

The entry point, we display a welcome message, and then copy the board and display it, it then checks if it is valid. It then tries to solve the puzzle (trysolve), and displays the board after each iteration. It then displays the end message.

### copyboard:

```copyboard:
#\$a0 is address of the board
li  \$t1, 81     #81 tiles in the board
li  \$t2, 'e'    #the empty square marker
la  \$t4, solved #have we solved it? (if there are no e then it is complete, unless there are errors)
clrE:
lb  \$t3, (\$a0)
bne \$t3, \$t2, notE  #Not an e, so we don't need to replace it
li  \$t3, ' '
sb  \$t3, (\$a0)
sb  \$zero, (\$t4)
notE:   addi    \$a0, \$a0, 1 #Next position in the board
subi    \$t1, \$t1, 1
bne \$t1, \$0, clrE
subi    \$a0, \$a0, 81
la  \$a1, board
li  \$t1, 9
copyboard1:         #Now we copy the entire board
lb  \$t0, (\$a0)  #Copy a vertical column
sb  \$t0, (\$a1)
lb  \$t0, 9(\$a0)
sb  \$t0, 16(\$a1)
lb  \$t0, 18(\$a0)
sb  \$t0, 32(\$a1)
lb  \$t0, 27(\$a0)
sb  \$t0, 48(\$a1)
lb  \$t0, 36(\$a0)
sb  \$t0, 64(\$a1)
lb  \$t0, 45(\$a0)
sb  \$t0, 80(\$a1)
lb  \$t0, 54(\$a0)
sb  \$t0, 96(\$a1)
lb  \$t0, 63(\$a0)
sb  \$t0, 112(\$a1)
lb  \$t0, 72(\$a0)
sb  \$t0, 128(\$a1)
subi    \$t1, \$t1, 1 #One less to column to do
bne \$t1, \$0, copyboard1
jr  \$ra```

Copy the board from the linear format into a 2d friendly format (replace the e with a space, as it is better for displaying the board). The board is laid out so that each row takes 16 bytes.

### displayBoard:

```#Display the board, uses seperators to make it display better
displayBoard:
la  \$a0, seperator  #+---+---+---+
li  \$v0, 4
syscall
move    \$a3, \$a0
la  \$a0, boardline  #|???|???|???|
move    \$a2, \$a0
la  \$a1, board
li  \$t0, 3
li  \$t1, 3
displayBoard1:          #copy over the ?
lb  \$t2, (\$a1)
sb  \$t2, 1(\$a0)
lb  \$t2, 1(\$a1)
sb  \$t2, 2(\$a0)
lb  \$t2, 2(\$a1)
sb  \$t2, 3(\$a0)

lb  \$t2, 3(\$a1)
sb  \$t2, 5(\$a0)
lb  \$t2, 4(\$a1)
sb  \$t2, 6(\$a0)
lb  \$t2, 5(\$a1)
sb  \$t2, 7(\$a0)

lb  \$t2, 6(\$a1)
sb  \$t2, 9(\$a0)
lb  \$t2, 7(\$a1)
sb  \$t2, 10(\$a0)
lb  \$t2, 8(\$a1)
sb  \$t2, 11(\$a0)    #display the line
syscall
addi    \$a1, \$a1, 16    #move onto the next line
subi    \$t1, \$t1, 1
bne \$t1, \$zero, displayBoard1
li  \$t1, 3
move    \$a0, \$a3    #display the seperator
syscall
move    \$a0, \$a2    #restore the boardline
subi    \$t0, \$t0, 1
bne \$t0, \$zero, displayBoard1
jr  \$ra```

The board has character graphics to represent the grid, and so we copy in the digits into the spaces and display each line.

### validBoard:

```validBoard:
#Check for multiple copies of a digit, in a row, column, or block
push    \$ra
la  \$a1, board
li  \$s0, 8      #column, row, and block to check
li  \$s1, '1'    #subtract form each to get bit
la  \$s2, counts #count how many occurences
li  \$s3, 2      #it will equal 2 at some point if there is an error
validBoard1:
jal checkHorizontal #check row
beq \$v0, \$zero, validBoard2 #no error found
la  \$a0, row    #error was in the row
jal validError  #display the error message
validBoard2:
jal checkVertical   #check column
beq \$v0, \$zero, validBoard3 #no error found
la  \$a0, column #display column message
jal validError
validBoard3:
jal checkBlock  #check for problems in a 3x3 block area
beq \$v0, \$zero, validBoard4 #no errors found
la  \$a0, block
jal validError
validBoard4:
subi    \$s0, \$s0, 1 #now check the previous row,column,block
bge \$s0, \$zero, validBoard1 #we still have some left to check
jr  \$ra

validError:
#\$a0 = "row ", "column ", "block "
#\$a1 = row#, column#, block#
li      \$v0, 4
syscall             #print
li  \$v0, 1
la  \$a0, errors
sb  \$v0, (\$a0)
print_int \$s4
la  \$a0, has
li      \$v0, 4
syscall             #print "has "
move    \$t0, \$s2
li  \$t1, 1
li  \$t2, 9
errorLoop:
lb  \$t3, (\$t0)      #get count
bgt \$s3, \$t3, notError
print_int \$t3
la  \$a0, space
li  \$v0, 4
syscall             #print space
print_int \$t1
la  \$a0, apos
li  \$v0, 4
syscall             #print 's
notError:
subi    \$t2, \$t2, 1
bne \$t2, \$zero, errorLoop
la  \$a0, endline
li      \$v0, 4
syscall             #print cr,lf
jr  \$ra

checkHorizontal:
#\$a1 = board
#\$s0 = row
#\$s1 = '1' (to subtract)
#\$s2 = counts
#\$s3 = 2 (for count error)
sw  \$zero, (\$s2)        #clear counts
sw  \$zero, 4(\$s2)
sw  \$zero, 8(\$s2)
sll \$t0, \$s0, 4     #multiply by 16
li  \$t1, 9
move    \$v0, \$zero      #no error
checkHorizontal1:
lb  \$t2, (\$t0)
sub \$t2, \$t2, \$s1
blt \$t2, \$zero, checkHorizontal2    #space, so can't be error
add \$t3, \$s2, \$t2       #get the digit
lb  \$t4, (\$t3)
addi    \$t4, \$t4, 1     #increment the count
sb  \$t4, (\$t3)
bne \$t4, \$s3, checkHorizontal2  #count not equal to 2
li  \$v0, 1          #an error occured
checkHorizontal2:
subi    \$t1, \$t1, 1
bne \$t1, \$zero, checkHorizontal1
jr  \$ra         #return

checkVertical:
#\$a1 = board
#\$s0 = column
#\$s1 = '1' (to subtract)
#\$s2 = counts
#\$s3 = 2 (for count error)
sw  \$zero, (\$s2)        #clear counts
sw  \$zero, 4(\$s2)
sw  \$zero, 8(\$s2)
li  \$t1, 9
move    \$v0, \$zero
checkVertical1:
lb  \$t2, (\$t0)
sub \$t2, \$t2, \$s1
blt \$t2, \$zero, checkVertical2  #space
add \$t3, \$s2, \$t2       #get the digit
lb  \$t4, (\$t3)
sb  \$t4, (\$t3)
bne \$t4, \$s3, checkVertical2    #count did not reach 2
li  \$v0, 1          #an error occured
checkVertical2:
subi    \$t1, \$t1, 1
bne \$t1, \$zero, checkVertical1
jr  \$ra         #return

checkBlock:
#\$a1 = board
#\$s0 = block
#\$s1 = '1' (to subtract)
#\$s2 = counts
#\$s3 = 2 (for count error)
sw  \$zero, (\$s2)        #clear counts
sw  \$zero, 4(\$s2)
sw  \$zero, 8(\$s2)
la  \$t0, blocks
sll \$t1, \$s0, 2     #multiply by 4
lw  \$t0, (\$t0)      #get the address of the block

la  \$t5, offsets        #offset to the next tile in the block
li  \$t1, 9
move    \$v0, \$zero      #no error
checkBlock1:
lb  \$t2, (\$t0)
sub \$t2, \$t2, \$s1
blt \$t2, \$zero, checkBlock2 #space means we don't need to check
lb  \$t4, (\$t3)
sb  \$t4, (\$t3)
bne \$t4, \$s3, checkBlock2
li  \$v0, 1          #an error occured
checkBlock2:
lb  \$t6, (\$t5)      #get the next offset
add \$t0, \$t0, \$t6       #update the position
subi    \$t1, \$t1, 1
bne \$t1, \$zero, checkBlock1
jr  \$ra         #return```

This checks the board for errors, by keeping count of how many times a digit occurs in the row / column / block.

Our tutors discuss about those sections in assembly language project help and also provide solutions for the related assignment questions. The registers speed up the processor operations, and the processor includes some internal memory storage locations. Students also learn the different categories of registers like General registers, Control registers, and Segment registers that help them solve many related assignment problems.

### attempt:

```attempt:
#make an attempt to solve
push    \$ra         #we will call routines, so save the return address
la  \$t9, changed        #did we make any changes
sb  \$zero, (\$t9)        #say no for now
la  \$a1, board      #the tiles
la  \$a2, solve      #the board layout (row, column, block for each element)
la  \$a3, possible       #possible values
li  \$s1, '1'        #subtract to get base
li  \$s3, 1
li  \$s2, 81         #81 tiles to check
li  \$s4, ' '
li  \$s6, 511        #9 bits all set
la  \$s7, bitstodigit
attempt1:
move    \$v0, \$zero      #which bits are set
lb  \$s0, 0(\$a2)
sll \$t0, \$s0, 4
jal testHorizontal      #check row
lb  \$s0, 1(\$a2)
add \$s5, \$s5, \$s0       #board position
lb  \$t0, (\$s5)
bne \$t0, \$s4, attempt2  #already got a value, so no point calculating
jal testVertical        #check column
lb  \$s0, 2(\$a2)
jal testBlock       #and check the block
xor \$v0, \$v0, \$s6       #we set, so now we invert (so only possible values remain)
sw  \$v0, (\$a3)      #store in the possible array
lb  \$v0, (\$v0)
sb  \$v0, (\$s5)      #update the board
beq \$v0, \$s4, attempt2  #if it was not a space
sb  \$s3, (\$t9)      #changed = 1
attempt2:
addi    \$a2, \$a2, 3     #update the solve
addi    \$a3, \$a3, 4     #the possible
subi    \$s2, \$s2, 1     #and the number of tiles
bne \$zero, \$s2, attempt1    #more tiles to process

pop \$ra         #restore the return address
jr  \$ra```

This checks each horizontal, vertical, and block, and constructs a bit mask of all the bits and then clears the ones it has encountered either in the same row, block or column. If that results in a single bit, then it has solved that square since it is the only possible choice.

Our assembly language experts provide assembly language project help to the students and guide them through every step from starting a project till the end of the project. Learners get help with assembly language project from our highly skilled and experienced experts and find their solutions to be the most accurate and precise that meets their requirement. We are always providing the best skilled experts for assignment solutions and students are found, availing most of its advantage. Students from all over the world take our help with assembly language homework for accurate solutions. You are at the right place if you need help with assembly language assignment within the deadline.