Make a 15-puzzle game(also called Game of Fifteen) using assembly language. It i
ID: 3738168 • Letter: M
Question
Make a 15-puzzle game(also called Game of Fifteen) using assembly language. It is a sliding puzzle game that consists of a frame of numbered square tiles in random order with one tile missing. -needs to be the 4x4 tiles (1-15)
-needs to be implemented in 8086/x86 intel 64 bit
-needs to use only 16 bit registers
-no macros -use tasm and dosbox
-needs to use arrow keys(up down left right) to move the tiles in the puzzle
-needs to tell the user if the user won the game
-needs to ask the user if the user wants to restart game
-needs to shuffle the numbers every time the user wants to restart the game
-give the user option to quit the game
-needs to show how many moves the user is making -put comments on what you're doing for each line of the code
-needs to be .asm file
Explanation / Answer
puzzle.asm
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov WORD PTR [rbp-8], 0
mov BYT PTR [rbp-1], 97
mov ax, 0
call clrscr
mov ax, 0
call Rst
mov ax, 0
call Logo
mov ax, 0
call Print
jmp .L2
.L9:
mov ax, 0
call gtch
mov BYT PTR [rbp-1], al
movsx ax, BYT PTR [rbp-1]
sub ax, 72
cmp ax, 42
ja .L2
mov ax, ax
mov rax, QWORD PTR .L4[0+rax*8]
jmp rax
.L4:
.quad .L3
.quad .L2
.quad .L2
.quad .L5
.quad .L2
.quad .L6
.quad .L2
.quad .L2
.quad .L7
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L8
.L7:
mov ax, 0
call Down
mov ax, 0
call Print
mov ax, 0
call Chck
jmp .L2
.L6:
mov ax, 0
call Right
mov ax, 0
call Print
mov ax, 0
call Chck
jmp .L2
.L5:
mov ax, 0
call Lft
mov ax, 0
call Print
mov ax, 0
call Chck
jmp .L2
.L3:
mov ax, 0
call Up
mov ax, 0
call Print
mov ax, 0
call Chck
jmp .L2
.L8:
mov ax, 0
call Rst
mov ax, 0
call Print
mov ax, 0
call Chck
nop
.L2:
cmp BYT PTR [rbp-1], 113
jn .L9
nop
lav
rt
.LC0:
.string " =============================================================================="
.LC1:
.string " This GAM Is Dsignd By ADMIN "
.LC2:
.string " Kys: Up"
.LC3:
.string " Down"
.LC4:
.string " Lft"
.LC5:
.string " Right "
.LC6:
.string " 'q' to Quit."
.LC7:
.string " Prss Any Ky To Continu"
Logo:
push rbp
mov rbp, rsp
mov ax, 0
call clrscr
mov di, OFFST FLAT:.LC0
mov ax, 0
call printf
mov di, OFFST FLAT:.LC1
mov ax, 0
call printf
mov di, OFFST FLAT:.LC0
mov ax, 0
call printf
mov di, OFFST FLAT:.LC2
mov ax, 0
call printf
mov di, OFFST FLAT:.LC3
mov ax, 0
call printf
mov di, OFFST FLAT:.LC4
mov ax, 0
call printf
mov di, OFFST FLAT:.LC5
call puts
mov di, OFFST FLAT:.LC6
mov ax, 0
call printf
mov di, OFFST FLAT:.LC7
mov ax, 0
call printf
mov ax, 0
call gtch
nop
pop rbp
rt
.LC8:
.string " "
.LC9:
.string " _____________________"
.LC10:
.string " | | | | |"
.LC11:
.string "%d"
.LC12:
.string " ---------------------"
.LC13:
.string " ~~~~~~~~~~~~~~~~~~~~~"
Print:
push rbp
mov rbp, rsp
mov ax, 0
call clrscr
mov di, OFFST FLAT:.LC8
call puts
mov di, OFFST FLAT:.LC9
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov si, 16
mov di, 27
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 16
mov di, 32
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+4]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 16
mov di, 37
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+8]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 16
mov di, 42
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+12]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov di, OFFST FLAT:.LC12
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov si, 20
mov di, 27
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+16]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 20
mov di, 32
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+20]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 20
mov di, 37
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+24]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 20
mov di, 42
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+28]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov di, OFFST FLAT:.LC12
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov si, 24
mov di, 27
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+32]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 24
mov di, 32
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+36]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 24
mov di, 37
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+40]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 24
mov di, 42
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+44]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov di, OFFST FLAT:.LC12
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov si, 28
mov di, 27
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+48]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 28
mov di, 32
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+52]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 28
mov di, 37
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+56]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov si, 28
mov di, 42
mov ax, 0
call gotoxy
mov ax, WORD PTR Gam[rip+60]
mov si, ax
mov di, OFFST FLAT:.LC11
mov ax, 0
call printf
mov di, OFFST FLAT:.LC10
mov ax, 0
call printf
mov di, OFFST FLAT:.LC13
mov ax, 0
call printf
nop
pop rbp
rt
Rst:
push rbp
mov rbp, rsp
mov WORD PTR [rbp-4], 15
mov WORD PTR [rbp-8], 0
jmp .L13
.L16:
mov WORD PTR [rbp-12], 0
jmp .L14
.L15:
mov ax, WORD PTR [rbp-4]
la dx, [rax-1]
mov WORD PTR [rbp-4], dx
mov dx, WORD PTR [rbp-12]
movsx rdx, dx
mov cx, WORD PTR [rbp-8]
movsx rcx, cx
sal rcx, 2
add rdx, rcx
mov WORD PTR Gam[0+rdx*4], ax
add WORD PTR [rbp-12], 1
.L14:
cmp WORD PTR [rbp-12], 3
jl .L15
add WORD PTR [rbp-8], 1
.L13:
cmp WORD PTR [rbp-8], 3
jl .L16
mov WORD PTR Gam[rip+60], 0
nop
pop rbp
rt
.LC14:
.string "Congratulations"
Chck:
push rbp
mov rbp, rsp
sub rsp, 32
mov WORD PTR [rbp-4], 0
mov WORD PTR [rbp-16], 0
cmp WORD PTR [rbp-16], 0
j .L18
add WORD PTR [rbp-20], 1
.L18:
mov WORD PTR [rbp-8], 0
jmp .L19
.L25:
mov WORD PTR [rbp-12], 0
jmp .L20
.L24:
add WORD PTR [rbp-4], 1
cmp WORD PTR [rbp-8], 3
jn .L21
cmp WORD PTR [rbp-12], 3
j .L28
.L21:
mov ax, WORD PTR [rbp-12]
cdq
mov dx, WORD PTR [rbp-8]
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov ax, WORD PTR Gam[0+rax*4]
cmp WORD PTR [rbp-4], ax
jn .L23
add WORD PTR [rbp-16], 1
.L23:
add WORD PTR [rbp-12], 1
.L20:
cmp WORD PTR [rbp-12], 3
jl .L24
jmp .L22
.L28:
nop
.L22:
add WORD PTR [rbp-8], 1
.L19:
cmp WORD PTR [rbp-8], 3
jl .L25
cmp WORD PTR [rbp-16], 15
jn .L26
mov si, 36
mov di, 32
mov ax, 0
call gotoxy
mov di, OFFST FLAT:.LC14
mov ax, 0
call printf
mov ax, 1
jmp .L27
.L26:
mov ax, 0
.L27:
lav
rt
Lft:
push rbp
mov rbp, rsp
mov WORD PTR [rbp-12], 0
jmp .L30
.L34:
mov WORD PTR [rbp-16], 0
jmp .L31
.L33:
mov ax, WORD PTR [rbp-16]
cdq
mov dx, WORD PTR [rbp-12]
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov ax, WORD PTR Gam[0+rax*4]
tst ax, ax
jn .L32
mov ax, WORD PTR [rbp-12]
mov WORD PTR [rbp-4], ax
mov ax, WORD PTR [rbp-16]
mov WORD PTR [rbp-8], ax
.L32:
add WORD PTR [rbp-16], 1
.L31:
cmp WORD PTR [rbp-16], 3
jl .L33
add WORD PTR [rbp-12], 1
.L30:
cmp WORD PTR [rbp-12], 3
jl .L34
cmp WORD PTR [rbp-8], 3
j .L36
mov ax, WORD PTR [rbp-8]
add ax, 1
cdq
mov dx, WORD PTR [rbp-4]
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov ax, WORD PTR Gam[0+rax*4]
mov dx, WORD PTR [rbp-8]
movsx rdx, dx
mov cx, WORD PTR [rbp-4]
movsx rcx, cx
sal rcx, 2
add rdx, rcx
mov WORD PTR Gam[0+rdx*4], ax
mov ax, WORD PTR [rbp-8]
add ax, 1
cdq
mov dx, WORD PTR [rbp-4]
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov WORD PTR Gam[0+rax*4], 0
.L36:
nop
pop rbp
rt
Right:
push rbp
mov rbp, rsp
mov WORD PTR [rbp-12], 0
jmp .L38
.L42:
mov WORD PTR [rbp-16], 0
jmp .L39
.L41:
mov ax, WORD PTR [rbp-16]
cdq
mov dx, WORD PTR [rbp-12]
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov ax, WORD PTR Gam[0+rax*4]
tst ax, ax
jn .L40
mov ax, WORD PTR [rbp-12]
mov WORD PTR [rbp-4], ax
mov ax, WORD PTR [rbp-16]
mov WORD PTR [rbp-8], ax
.L40:
add WORD PTR [rbp-16], 1
.L39:
cmp WORD PTR [rbp-16], 3
jl .L41
add WORD PTR [rbp-12], 1
.L38:
cmp WORD PTR [rbp-12], 3
jl .L42
cmp WORD PTR [rbp-8], 0
j .L44
mov ax, WORD PTR [rbp-8]
sub ax, 1
cdq
mov dx, WORD PTR [rbp-4]
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov ax, WORD PTR Gam[0+rax*4]
mov dx, WORD PTR [rbp-8]
movsx rdx, dx
mov cx, WORD PTR [rbp-4]
movsx rcx, cx
sal rcx, 2
add rdx, rcx
mov WORD PTR Gam[0+rdx*4], ax
mov ax, WORD PTR [rbp-8]
sub ax, 1
cdq
mov dx, WORD PTR [rbp-4]
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov WORD PTR Gam[0+rax*4], 0
.L44:
nop
pop rbp
rt
Up:
push rbp
mov rbp, rsp
mov WORD PTR [rbp-12], 0
jmp .L46
.L50:
mov WORD PTR [rbp-16], 0
jmp .L47
.L49:
mov ax, WORD PTR [rbp-16]
cdq
mov dx, WORD PTR [rbp-12]
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov ax, WORD PTR Gam[0+rax*4]
tst ax, ax
jn .L48
mov ax, WORD PTR [rbp-12]
mov WORD PTR [rbp-4], ax
mov ax, WORD PTR [rbp-16]
mov WORD PTR [rbp-8], ax
.L48:
add WORD PTR [rbp-16], 1
.L47:
cmp WORD PTR [rbp-16], 3
jl .L49
add WORD PTR [rbp-12], 1
.L46:
cmp WORD PTR [rbp-12], 3
jl .L50
cmp WORD PTR [rbp-4], 3
j .L52
mov ax, WORD PTR [rbp-4]
la dx, [rax+1]
mov ax, WORD PTR [rbp-8]
cdq
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov ax, WORD PTR Gam[0+rax*4]
mov dx, WORD PTR [rbp-8]
movsx rdx, dx
mov cx, WORD PTR [rbp-4]
movsx rcx, cx
sal rcx, 2
add rdx, rcx
mov WORD PTR Gam[0+rdx*4], ax
mov ax, WORD PTR [rbp-4]
la dx, [rax+1]
mov ax, WORD PTR [rbp-8]
cdq
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov WORD PTR Gam[0+rax*4], 0
.L52:
nop
pop rbp
rt
Down:
push rbp
mov rbp, rsp
mov WORD PTR [rbp-12], 0
jmp .L54
.L58:
mov WORD PTR [rbp-16], 0
jmp .L55
.L57:
mov ax, WORD PTR [rbp-16]
cdq
mov dx, WORD PTR [rbp-12]
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov ax, WORD PTR Gam[0+rax*4]
tst ax, ax
jn .L56
mov ax, WORD PTR [rbp-12]
mov WORD PTR [rbp-4], ax
mov ax, WORD PTR [rbp-16]
mov WORD PTR [rbp-8], ax
.L56:
add WORD PTR [rbp-16], 1
.L55:
cmp WORD PTR [rbp-16], 3
jl .L57
add WORD PTR [rbp-12], 1
.L54:
cmp WORD PTR [rbp-12], 3
jl .L58
cmp WORD PTR [rbp-4], 0
j .L60
mov ax, WORD PTR [rbp-4]
la dx, [rax-1]
mov ax, WORD PTR [rbp-8]
cdq
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov ax, WORD PTR Gam[0+rax*4]
mov dx, WORD PTR [rbp-8]
movsx rdx, dx
mov cx, WORD PTR [rbp-4]
movsx rcx, cx
sal rcx, 2
add rdx, rcx
mov WORD PTR Gam[0+rdx*4], ax
mov ax, WORD PTR [rbp-4]
la dx, [rax-1]
mov ax, WORD PTR [rbp-8]
cdq
movsx rdx, dx
sal rdx, 2
add rax, rdx
mov WORD PTR Gam[0+rax*4], 0
.L60:
nop
pop rbp
rt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.