sanmianti / assemblylanguagetest Goto Github PK
View Code? Open in Web Editor NEW王爽《汇编语言》第三版课后实验及检测点答案。
王爽《汇编语言》第三版课后实验及检测点答案。
; Define constants
PACMAN_X equ 10
PACMAN_Y equ 10
GHOST_X equ 20
GHOST_Y equ 20
DOTS equ 10
; Define data section
section .data
dots_remaining dw DOTS
pacman_x dw PACMAN_X
pacman_y dw PACMAN_Y
ghost_x dw GHOST_X
ghost_y dw GHOST_Y
; Define code section
section .text
global _start
_start:
; Initialize screen
call clear_screen
call draw_pacman
call draw_ghost
call draw_dots
; Main game loop
game_loop:
; Move Pac-Man
call move_pacman
; Check for collision with ghost
call check_collision
; Check for victory
call check_victory
; Wait for key press and handle input
call handle_input
jmp game_loop
; Clear the screen
clear_screen:
mov ah, 0
mov al, 3
int 10h
ret
; Draw Pac-Man at current position
draw_pacman:
mov ah, 0ch
mov al, 00001111b
mov cx, [pacman_x]
mov dx, [pacman_y]
int 10h
ret
; Draw ghost at current position
draw_ghost:
mov ah, 0ch
mov al, 00001100b
mov cx, [ghost_x]
mov dx, [ghost_y]
int 10h
ret
; Draw dots on screen
draw_dots:
mov ah, 0ch
mov al, 00001111b
mov cx, 5
mov dx, 5
dots_loop:
int 10h
add cx, 10
dec word [dots_remaining]
cmp [dots_remaining], 0
jne dots_loop
ret
; Move Pac-Man based on user input
move_pacman:
; Get user input
mov ah, 0
int 16h
cmp al, 'w'
je move_up
cmp al, 's'
je move_down
cmp al, 'a'
je move_left
cmp al, 'd'
je move_right
ret
move_up:
sub word [pacman_y], 1
call draw_pacman
ret
move_down:
add word [pacman_y], 1
call draw_pacman
ret
move_left:
sub word [pacman_x], 1
call draw_pacman
ret
move_right:
add word [pacman_x], 1
call draw_pacman
ret
; Check for collision between Pac-Man and ghost
check_collision:
cmp [pacman_x], [ghost_x]
je collision_x
cmp [pacman_y], [ghost_y]
je collision_y
ret
collision_x:
cmp word [pacman_y], [ghost_y]
je game_over
ret
collision_y:
cmp word [pacman_x], [ghost_x]
je game_over
ret
; Check for victory condition
check_v
; Check if all dots have been eaten
check_victory:
cmp [dots_remaining], 0
jne continue_game
; Victory screen
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, victory_message
int 21h
jmp end_game
continue_game:
ret
; Handle user input
handle_input:
; Check if key has been pressed
mov ah, 1
int 16h
jz no_input
; Handle input
cmp al, 'q'
je end_game
jmp no_input
no_input:
ret
; Game over screen
game_over:
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, game_over_message
int 21h
jmp end_game
; End the game
end_game:
mov ah, 4ch
mov al, 0
int 21h
; Define messages
victory_message db 'You won!', 0
game_over_message db 'Game over.', 0
; Define constants
PACMAN_X equ 10
PACMAN_Y equ 10
GHOST_X equ 20
GHOST_Y equ 20
DOTS equ 10
; Define data section
section .data
dots_remaining dw DOTS
pacman_x dw PACMAN_X
pacman_y dw PACMAN_Y
ghost_x dw GHOST_X
ghost_y dw GHOST_Y
; Define code section
section .text
global _start
_start:
; Initialize screen
call clear_screen
call draw_pacman
call draw_ghost
call draw_dots
; Main game loop
game_loop:
; Move Pac-Man
call move_pacman
; Check for collision with ghost
call check_collision
; Check for victory
call check_victory
; Wait for key press and handle input
call handle_input
jmp game_loop
; Clear the screen
clear_screen:
mov ah, 0
mov al, 3
int 10h
ret
; Draw Pac-Man at current position
draw_pacman:
mov ah, 0ch
mov al, 00001111b
mov cx, [pacman_x]
mov dx, [pacman_y]
int 10h
ret
; Draw ghost at current position
draw_ghost:
mov ah, 0ch
mov al, 00001100b
mov cx, [ghost_x]
mov dx, [ghost_y]
int 10h
ret
; Draw dots on screen
draw_dots:
mov ah, 0ch
mov al, 00001111b
mov cx, 5
mov dx, 5
dots_loop:
int 10h
add cx, 10
dec word [dots_remaining]
cmp [dots_remaining], 0
jne dots_loop
ret
; Move Pac-Man based on user input
move_pacman:
; Get user input
mov ah, 0
int 16h
cmp al, 'w'
je move_up
cmp al, 's'
je move_down
cmp al, 'a'
je move_left
cmp al, 'd'
je move_right
ret
move_up:
sub word [pacman_y], 1
call draw_pacman
ret
move_down:
add word [pacman_y], 1
call draw_pacman
ret
move_left:
sub word [pacman_x], 1
call draw_pacman
ret
move_right:
add word [pacman_x], 1
call draw_pacman
ret
; Check for collision between Pac-Man and ghost
check_collision:
cmp [pacman_x], [ghost_x]
je collision_x
cmp [pacman_y], [ghost_y]
je collision_y
ret
collision_x:
cmp word [pacman_y], [ghost_y]
je game_over
ret
collision_y:
cmp word [pacman_x], [ghost_x]
je game_over
ret
; Check for victory condition
check_victory:
cmp [dots_remaining], 0
jne continue_game
; Victory screen
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, victory_message
int 21h
jmp end_game
continue_game:
ret
; Handle user input
handle_input:
; Check if key has been pressed
mov ah, 1
int 16h
jz no_input
; Handle input
cmp al, 'q'
je end_game
jmp no_input
no_input:
ret
; Game over screen
game_over:
mov ah, 0
mov al, 2
mov bh, 0
mov dh, 12
mov dl, 32
int 10h
mov ah, 9
mov dx, game_over_message
int 21h
jmp end_game
; End the game
end_game:
mov ah, 4ch
mov al, 0
int 21h
; Define messages
victory_message db 'You won!', 0
game_over_message db 'Game over.', 0
`C:>link
Microsoft (R) Overlay Linker Version 3.69
Copyright (C) Microsoft Crop 1983-1988. All rights reserved.
Object Modules [.OBJ]: TEST3.OBJ;
LINK : warning L4021: no stack segment
LINK : fatal error L1083: cannot open run file
`
实验七可以定义一个栈段做中转, push cx ... pop cx, 减少一次循环吧
倒数第二行,ax应该是=D810H
表格倒数第四行,
此处应该是 add ah,ah
第一空代码为:mov ax, cx
这里应该是是 mov ax,cs
我个人认为检测点3.1最后一句代码 add al,bl 执行后 ax 结果为0012H
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.