Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is assembly programming using Kip Irvine. Please help. Purpose: To use CMP

ID: 3712646 • Letter: T

Question

This is assembly programming using Kip Irvine. Please help.

Purpose:    To use CMP and conditional jumps

Overview of Craps

The game of craps uses two 6-sided dice, where each die contains a number between 1 and 6. The total of the two sides that face up is the total for a roll of the dice.

The first roll that a player throws in Craps has three possible outcomes: they can win, they can lose, or they will continue to roll.

On the first roll, if the player gets a 7 or 11 that is a win.

On the first roll, if the player gets a 2, 3, or 12 that is a loss.

On the first roll, if the player gets anything else (4,5,6,8,9,10) then that is their mark(point) and they need to continue to roll trying to get that mark(point).

Lab 5

Simulate a “first roll” of two dice in Craps. For each “first roll” determine if the roll is a Win, a Loss, or a Mark.

Tally the occurrence of each possibility. After the loop, display the counts for each possibility.

Do this for the number of rolls the user wants. (you can assume for this lab they will not enter a number <= 0)

See the “Sample Runs” next page

Grading Rubric

• Prompting user for number of rolls (10 points)

• Looping on number of rolls (10 points)

• Inside loop:

"rolling" 2 dice (10 points)

Showing the dice and category (Win/Lose/Mark) (10 points)

Incrementing proper counters (15 points)

• After loop:

Displaying tallies (10 points)

• Comments for: your name up top, comments for each data declaration, and each command (or logical grouping) in main (20 points)

• "meaningful variable names" (8 points)

• Neat Indenting (body of main neatly indented) (7 points)

Submitting the Lab

Post the source file as a .txt with sample runs (more than 1) commented afterwards to blackboard.

Sample Run:

How many rolls would you like to see: 1

3 + 6 = 9 Mark

Wins: 0

Losses: 0

Marks: 1

Press any key to continue . . .

Another Sample Run:

How many rolls would you like to see: 5

5 + 4 = 9 Mark

6 + 6 = 12 Loss

2 + 5 = 7 Win

3 + 1 = 4 Mark

1 + 3 = 4 Mark

Wins: 1

Losses: 1

Marks: 3

Press any key to continue . . .

Another Sample Run:

How many rolls would you like to see: 15

5 + 3 = 8 Mark

6 + 1 = 7 Win

6 + 5 = 11 Win

4 + 3 = 7 Win

1 + 1 = 2 Loss

3 + 3 = 6 Mark

1 + 6 = 7 Win

2 + 4 = 6 Mark

1 + 6 = 7 Win

5 + 3 = 8 Mark

4 + 2 = 6 Mark

5 + 4 = 9 Mark

5 + 3 = 8 Mark

4 + 3 = 7 Win

5 + 3 = 8 Mark

Wins: 6

Losses: 1

Marks: 8

Press any key to continue . . .

Explanation / Answer

INCLUDE Irvine32.inc

.data

diceOne                     DWORD ?

diceTwo                     DWORD ?

win                         DWORD 7, 11

lose                        DWORD 2, 3, 12

mark                        DWORD 4, 5, 6, 8, 9, 10

markCounter                 DWORD ?

userInput                   BYTE 'How many rolls would you like to see: ', 0

numRolls                    DWORD ?

printWon                    BYTE 'Won: ', 0

wonCounter                  DWORD ?

printWin                   BYTE ' Win', 0

printLost                   BYTE 'Loss: ', 0

lostCounter                 DWORD ?

printLoss                   BYTE ' Loss', 0

printTotal                  BYTE 'Total: ', 0

space                       DWORD ' ', 0

printPlus                   BYTE ' + ', 0

printMark                   BYTE ' Mark ', 0

.code

main PROC

    call randomize                      ; set random seed

    mov ecx, 6                          ; counter set to 6

    mov edx, offset userInput           ; print string

    call writeString

    call readInt                        ; read input

    mov numRolls, eax                   ; store input in variable

    mov ecx, numRolls                  

    mov eax, 0

    mov edi, offset win

    call gamesRolled

    exit

main ENDP

;number of games rolled based on user input

gamesRolled PROC uses eax ecx

DICEROLLS:

    call crlf

                                ;diceOne roll

    mov eax, 5                  ;move value into eax to pass as parameter for randomrange

    call randomRange            ;randomrange stored in eax 0-5

    inc eax

    mov diceOne, eax            ;mov the value of randomrange into variable

    call writeDec      

    push edx                    ;push edx off stack to print space

    mov edx, OFFSET printPlus

    call writeString

    pop edx

                                ;diceTwo roll

    mov eax, 6

    call randomRange

    inc eax

    mov diceTwo, eax

    call writeDec

    add eax, diceOne            ; add diceOne roll to diceTwo roll

    cmp eax, win                ; comp eax value to win

    je wins

    cmp eax, lose

    je losses

    cmp eax, mark

    je marks

    LOOP DICEROLLS

    ret

gamesRolled ENDP

wins PROC uses edi ecx

    mov edi, offset win

    mov ecx, lengthof win

    cmp eax, [edi]

    add edi, type win

    push edx

    mov edx, offset printWin

    call writeString

    pop edx

    jmp gamesRolled

    ret

wins ENDP

losses PROC uses edi ecx

    mov edi, offset lose

    mov ecx, lengthof lose

    cmp eax, [edi]

    add edi, type lose

    push edx

    mov edx, offset printLoss

    call writeString

    pop edx

    jmp gamesRolled

    ret

losses ENDP

marks PROC uses edi ecx

    mov edi, offset lose

    mov ecx, lengthof lose

    cmp eax, [edi]

    add edi, type lose

    push edx

    mov edx, offset printMark

    call writeString   

    pop edx

    jmp gamesRolled

    ret

marks ENDP

END main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote