Question

Translate the following C code into assembly

BIT POlG PoNG 井defire led (c).0, to onsgred int.delog (volal.le udigred aぼ do a-- reluin a1 Ind moin (voud) whale to) for ( 201 x delaq ta) i P1001 led tOi

0 0
Add a comment Improve this question Transcribed image text
Answer #1
org 100h
        jmp start

;functions area

WindowColor    Macro X1,Y1,X2,Y2,Color
Mov Ax,0600h
Mov Cl,X1
Mov Ch,Y1
Mov Dl,X2
Mov Dh,Y2
Mov Bh,Color
Int 10h
EndM

printstring     Macro       Adr
MOV DX, OFFSET Adr
MOV AH, 9
INT 21h
EndM
goto        macro           x,y
MOV DH, x   ;ROW
MOV DL, y   ;COLUMN
MOV AH, 02H
INT 10H
EndM
curser      macro       x,y
MOV DH, x   ;ROW
MOV DL, y   ;COLUMN
MOV AH, 02H
INT 10H
EndM
printpixel      macro       x,y,color,p
mov bh, p
mov cx, x
mov dx, y
mov al, color
mov ah, 0ch
int 10h
EndM

delay   macro   time
mov cx,time
mov dx,4240h
mov ah,086h
int 15h
EndM
;----------------------------------
print_batt PROC
PRINTBATT:
MOV DX, player1top
print:
INC player1count
printpixel 10, DX, 0100B,1
INC DX
INC player1count
CMP player1count, 150
JNE print
SUB player1count, 150
RET
print_batt ENDP

print_com PROC
MOV DX, comtop
printcompo:
INC comcount
printpixel 308, DX, 0001b,1
INC DX
INC comcount
CMP comcount, 150
JNE printcompo
SUB comcount, 150
RET
print_com ENDP

print_ball PROC
printpixel ballx, bally, 00000001b,3
DEC ballx
DEC bally
printpixel ballx, bally, 00000001b,3
INC ballx
printpixel ballx, bally, 00000001b,3
sub ballx, 2
DEC bally
printpixel ballx, bally, 00000001b,3
inc ballx
printpixel ballx, bally, 00000001b,3
inc ballx
printpixel ballx, bally, 00000001b,3
inc ballx
printpixel ballx, bally, 00000001b,3

printpixel ballx, bally, 00000001b,3
DEC bally
sub ballx, 2
printpixel ballx, bally, 00000001b,3
INC ballx
printpixel ballx, bally, 00000001b,3
DEC bally
DEC bally
printpixel ballx, bally, 00000001b ,3

RET
print_ball ENDP

clearscreen proc
MOV AL, 13H ;changes the num of pixels to 640X480 with 16 colors
MOV AH, 0
INT 10H

ret
clearscreen ENDP

reprint     proc
call clearscreen
call print_batt
call print_com

ret
reprint     ENDP

baseprint   proc
    mov base, 0
printbase:
printpixel base, 0, 2, 2
INC base
CMP base, 320
JNE printbase

mov base, 0
printdownbase:
printpixel base, 199, 2, 2
INC base
CMP base, 320
JNE printdownbase

mov base, 0
printleftbase:
printpixel 0, base, 2, 2
INC base
CMP base, 199
JNE printleftbase

mov base, 0
printrightbase:
printpixel 319, base, 2, 2
INC base                   
CMP base, 199
JNE printrightbase

    ret
baseprint   EndP

;-----------------------ball movement proc-------------------

;main move
balloop         macro       move
call move
CALL hitcheck
JMP checkahit
EndM

;LEFT UP
bdleftup    PROC
call reprint
sub  ballx, 14
dec  bally
CALL print_ball

MOV lastaction, bdleftup

RET
bdleftup    ENDP

bdleftupreverse     proc
    ADD ballx, 11
    INC bally
RET
bdleftupreverse    ENDP


;LEFT DOWN
bdleftdown    PROC
call reprint
sub  ballx, 11
ADD  bally, 10
CALL print_ball
MOV lastaction, bdleftdown
RET
bdleftdown    ENDP

bdleftdownreverse     proc
    ADD ballx, 11
    DEC bally
RET
bdleftdownreverse    ENDP

;RIGHT UP
bdrightup    PROC
call reprint
ADD  ballx, 11
DEC  bally
CALL print_ball
MOV lastaction, bdrightup
RET
bdrightup    ENDP

bdrightupreverse     proc
    SUB ballx, 11
    INC bally
RET
bdrightupreverse    ENDP

;RIGHT DOWN
bdrightdown    PROC
call reprint
ADD  ballx, 10
ADD  bally, 11
CALL print_ball
MOV lastaction, bdrightdown
RET
bdrightdown    ENDP

bdrightdownreverse     proc
    SUB ballx, 11
    DEC bally
RET
bdrightdownreverse    ENDP

hitcheck    PROC
;------batt and com check-------
MOV BH, 2H
MOV DX, ballx
MOV CX, bally
SUB CX, 2
MOV AH, 0Dh      
INT 10H

CMP AL, 1
JE hitmovement
CMP AL, 3
JE comhitmovement

MOV BH, 2H
MOV DX, ballx
MOV CX, bally
ADD CX, 2
MOV AH, 0Dh            
INT 10H

CMP AL, 1
JE hitmovement
CMP AL, 3
JE comhitmovement

MOV BH, 2H
MOV DX, ballx
MOV CX, bally
SUB DX, 2
MOV AH, 0Dh      
INT 10H

CMP AL, 1
JE hitmovement
CMP AL, 3
JE comhitmovement

MOV BH, 2H
MOV DX, ballx
MOV CX, bally
ADD DX, 2
MOV AH, 0Dh      
INT 10H

CMP AL, 1
JE hitmovement
CMP AL, 3
JE comhitmovement

;------base check-------

CMP bally, 1
JB upbasehitmovement
JE upbasehitmovement

CMP ballx, 1
JB leftbasehitmovement
JE leftbasehitmovement

CMP bally, 199
JA downbasehitmovement
JE downbasehitmovement

CMP ballx, 315
JA rightbasehitmovement
JE rightbasehitmovement

JMP nonhit

hitmovement:
MOV AH, 2CH      ;TIMER
INT 21H    
CMP DH, 30
JA NC1 
JB NC13
NC13:
balloop bdrightup    ;BALLOOP CONFIGURATION
JMP checkahit  
NC1:
balloop bdrightdown    ;BALLOOP CONFIGURATION
JMP checkahit

comhitmovement:
MOV AH, 2CH      ;TIMER
INT 21H    
CMP DH, 30
JA NC2
balloop bdleftdown    ;BALLOOP CONFIGURATION  
NC2:
balloop bdleftup    ;BALLOOP CONFIGURATION
JMP checkahit

upbasehitmovement:
balloop bdrightdown 
JMP checkahit

downbasehitmovement:
balloop bdrightup 
JMP checkahit

rightbasehitmovement:
JMP END

leftbasehitmovement:
JMP END

nonhit:
ret
hitcheck    EndP

;----------------------------------data area-------------------------

yay              DB       "                ,-.----.       ,----..            ,--.               ", 13, 10
DB       "                \    /  \     /   /   \         ,--.'|  ,----..      ", 13, 10
DB       "                |   :    \   /   .     :    ,--,:  : | /   /   \     ", 13, 10
DB       "                |   |  .\ : .   /   ;.  \,`--.'`|  ' :|   :     :    ", 13, 10
DB       "                .   :  |: |.   ;   /  ` ;|   :  :  | |.   |  ;. /    ", 13, 10
DB       "                |   |   \ :;   |  ; \ ; |:   |   \ | :.   ; /--`     ", 13, 10
DB       "                |   : .   /|   :  | ; | '|   : '  '; |;   | ;  __    ", 13, 10
DB       "                ;   | |`-' .   |  ' ' ' :'   ' ;.    ;|   : |.' .'   ", 13, 10
DB       "                |   | ;    '   ;  \; /  ||   | | \   |.   | '_.' :   ", 13, 10
DB       "                 :   ' |     \   \  ',  / '   : |  ; .''   ; : \  |  ", 13, 10
DB       "                 :   : :      ;   :    /  |   | '`--'  '   | '/  .'  ", 13, 10
DB       "                |   | :       \   \ .'   '   : |      |   :    /     ", 13, 10
DB       "                `---'.|        `---`     ;   |.'       \   \ .'      ", 13, 10
DB       "                  `---`                  '---'          `---`        ", 13, 10, '$'
startmsg         DB       "Click Space To Start!$"
lidor            DB       "Created By LidorMotai. Inspired By ATARI.$"
wrongb           DB       "You have clicked the wrong button!$"
c1               DB       0
c2               DB       21

player1top       DW       4  ;top pixel
player1count     DW       0

comtop           DW       110  ;top com pixel
comcount         DW       0

ballx            DW       150
bally            DW       90

p1score          DW       0
p2score          DW       0

lastaction       DW       bdleftup

base             dw       0

start:

;----------START PAGE-------------
MOV AL, 1 ;PAGE NUMBER
MOV AH, 05H
INT 10H

WindowColor 0,0,80,25,01ch

;PRINT "PONG" TO SCREEN
MOV BH, 1
printstring yay

;SET CURSOR POSITION TO STARTMSG
goto 14,29

;PRINT STARTMSG
printstring startmsg

;SET CURSOR POSITION TO lidor
MOV BH, 1   ;PAGE
curser  20, 20

;PRINT CREATOR(LidorMotai)

MOV DX, OFFSET lidor
MOV AH, 09H
INT 21H

;SET CURSOR POSITION TO lidor
MOV BH, 0   ;PAGE
curser  15,40

;WAIT FOR PLAYER TO CLICK SPACE

MOV AH, 07H
INT 21H
CMP AL, 20H
JNE wrong
JE right

wrong:
MOV BH, 0   ;PAGE
MOV DH, 16   ;ROW
MOV DL, 23   ;COLUMN
MOV AH, 02H
INT 10H

MOV DX, OFFSET wrongb
MOV AH, 09H
INT 21H
jmp end

right:

;-------------------GAME PAGE-------------------

MOV AL, 2 ;PAGE NUMBER
MOV AH, 05H
INT 10H

MOV AX, 13H ;changes the num of pixels to 640X480 with 16 colors
INT 10H

; - - - - - - - - - - Game Code - - - - - - - -


CALL print_ball
CALL print_com
CALL print_batt

balloop bdleftup

;PLAYER1 - CLICK?
checkahit:


p1movecheck:

; PRINT BASE
CALL baseprint

delay   00000001b
;
;CMP p1score, 1
;JE score

MOV AL, 0
MOV AH, 01H
INT 16H
JZ noclick
MOV AH, 00H
INT 16H

CMP AH, 48H
JE P1UP
CMP AH, 50H
JE P1DOWN


P1UP:

CMP player1top, 4
JE  checkahit

MOV AL, 13H ;changes the num of pixels to 640X480 with 16 colors
MOV AH, 0
INT 10H

CALL print_com

MOV AX, player1top
SUB AX, 4
MOV player1top, AX

balloop lastaction
JMP hitcheck

CALL print_batt
JMP checkahit

P1DOWN:

CMP player1top, 120
JE  checkahit

MOV AL, 13H
MOV AH, 0
INT 10H

CALL print_com

MOV AX, player1top
ADD AX, 4
MOV player1top, AX

CALL print_batt

balloop lastaction
JMP hitcheck

JMP checkahit

noclick:
balloop lastaction
JMP hitcheck

score:
call clearscreen

END:

;MOV AH, 2CH      ;TIMER
;INT 21H    
;
;CMP DH, 30
;JA NC1
;balloop bdrightup    ;BALLOOP CONFIGURATION  
;NC1:
;balloop bdrightdown    ;BALLOOP CONFIGURATION
Add a comment
Know the answer?
Add Answer to:
Translate the following C code into assembly BIT PONG #define Led(1) = 0.01 #define Led(2) =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Translate the following C code to MIPS assembly code. Question 1) int counter = 0; void...

    Translate the following C code to MIPS assembly code. Question 1) int counter = 0; void change_global(int value) { counter = counter + value; } void main() { change_global(5); change_global(10); }

  • Translate the following C code into RISC-V Assembly. (no need to implement the prints just use...

    Translate the following C code into RISC-V Assembly. (no need to implement the prints just use ecall) int a[] = {2,2,5,3,4,8,3}; int b[] = {1,4,2,0,-1,5,4}; int z[7]; void multiply(int* a, int* b, int* c, int d) { for (int i=0; i < d; i++) { c[i] = a[i] * b[i]; } } int main() { int n = 7; multiply(a,b,z,n); printf("%s", "res: "); for (int i = 0; i < z; i++) { printf("%d", d[i]); } printf("\n"); return 0; }

  • ARM assembly using breadboard Ladder Game - This game involves a setup of LEDs in a...

    ARM assembly using breadboard Ladder Game - This game involves a setup of LEDs in a row and a button. The goal is to get from the bottom led all the way to the top without them resetting. The LEDs will flash and you can only move up one led at a time, when the led is lit up, or else you get reset to the bottom. code in C please convert to ARM assembly #include <stdio.h> #include <stdlib.h> #include...

  • Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C...

    Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C code to MIPS assembly language. void main() { int i, sum, begin, end; for(i=0; i < 5; i++){ scanf(“%d, %d”, &begin, &end); sum = accum_range(begin, end); printf(“sum[%d: %d] = %d\n”, begin, end, sum); } int accum_range(int a, int b){ return accum (b) - accum(a); } int accum(int final) { int sum = 0; for (int I = 1; I <= final; I = I...

  • Please comment and or provide information on what each function or line does within the following...

    Please comment and or provide information on what each function or line does within the following code. The code is a Arduino Atmega C programming language code which which creates a piano keyboard outputting different frequencies per. I would really appreciate a detailedf explanation on what each function and line does as I am a beginner and need to use this within lab. volatile unsigned char *TCCR1A = (unsigned char *) 0x80; /* Address location for Timer/Counter Control Register A....

  • I need MIPS code for this program Translate the following C++ program to MIPS assembly program...

    I need MIPS code for this program Translate the following C++ program to MIPS assembly program (Please explain each instruction of your code by a comment and submit a .asm file) // Example program #include <iostream> #include <string> using namespace std; int main() { const int ADULT_CHOICE= 1, CHILD_CHOICE= 2, SENIOR_CHOICE= 3, QUIT_CHOICE= 4, ADULT = 250, CHILD = 200, SENIOR = 350; int choice, months; int charges = 0; do { cout <<"\n\t\tHealth Club Membership Menu\n\n" <<"1. Standard Adult...

  • its brr[8] (40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program...

    its brr[8] (40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program (including main and all the required directives). You can use any register. You must comply, however, with the convention of register usage. Before writing your code perform an explicit register allocation phase. Note that the C snippet is int arr[8]; int brr[4]-{1, 2, 3, 4, 5, 6, 7, 8) int i-8; while (i>-0) arrli]-brr[i-); (40%) Convert the following C-pseudo code into MIPS assembly code...

  • need help converting a code in c++ over into MARIE assembly language // C++ program to...

    need help converting a code in c++ over into MARIE assembly language // C++ program to find (a^b) mod n for 'a' #include<bits/stdc++.h> using namespace std; // calculate a%n unsigned int aModM(string s, unsigned int mod) {    unsigned int number = 0;    for (unsigned int i = 0; i < s.length(); i++)    {        // (s[i]-'0') gives the digit value and form        // the number        number = (number*10 + (s[i] - '0'));...

  • 4. (a) Translate the following pseudo-code into MIPS assembly code. Assume that A, B, C are...

    4. (a) Translate the following pseudo-code into MIPS assembly code. Assume that A, B, C are arrays of size N elements, indexed 0..N-1 I=I; WHILE(I<N AND A[I]<B[I]) C[I] = A[I] + B[I-1]

  • Translate the following C program to Pep/9 assembly language. #include <stdio.h> const int limit = 5;...

    Translate the following C program to Pep/9 assembly language. #include <stdio.h> const int limit = 5; int main() { int number; scanf("%d",&number); while (number < limit){ number++; printf("%d",number); } return 0; }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT