At an ice-skating competition, skaters are assessed by a panel of 6 judges each
ID: 3594385 • Letter: A
Question
At an ice-skating competition, skaters are assessed by a panel of 6 judges each of whom gives a performance an integer score from 0 to 10. The overall score is computed by discarding the highest and lowest of the 6 scores and averaging the remaining 4. Write and test a Pep/9 assembly code program that input the scores for two skaters A and B and then determines the winner. There may be a tie. Examples Scores for A: 10 10 9 5 8 10 Scores for B: 8 10 8 9 10 5 A wins! A average: 9.25 B average: 8.75Explanation / Answer
start:
mov eax, 4 // Avg of just 4 elements
mov ebx,0 // store sum and avg of A
mov ecx,0 // store sum and avg of B
mov edx,playerA // array of scores of player A
add edx,1 // inc register to point to 2nd element
loopA: // executes from 2-5 elements of the array
add ebx, [edx] // add each element to ebx
add edx, 1 // increment array
dec eax // decrement counter
jnz loopA // if eax > 0, add next element
mov eax,4 // reset eax to 4
mov edx,player // array of scores of player B
add edx,1 // inc register to point to 2nd element
loopB:
add ecx, [edx]
add edx, 1
dec eax
jnz loopB
div ebx,4 // divide sum by 4 to get avg
div ecx,4
cmp ebx,ecx // compare avg of both the players
je equal // if equals then tie
cmp ebx,ecx
jlt less // if ebx<ecx, B won
jmp more // if ebx > ecx, A won
equal:
msg db “Both the players tie”
less:
msg db “Player B won”
more:
msg db “Player A won”
EXIT:
_exit
If this helps please give a thumbs up. Happy Chegging!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.