Giter VIP home page Giter VIP logo

assemblylanguagetest's People

Contributors

fnmain avatar higgins995 avatar sanmianti avatar smallzhong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

assemblylanguagetest's Issues

Comsc

; 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

实验7

实验七可以定义一个栈段做中转, push cx ... pop cx, 减少一次循环吧

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.