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

Please help me convert c code to pseudo code #include <stdio.h> #include <stdlib

ID: 3727290 • Letter: P

Question

Please help me convert c code to pseudo code

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#define SUITS 4

#define FACES 13

#define CARDS 52

void shuffle(unsigned int deck[][FACES]);

void deal(unsigned int deck[][FACES], unsigned int hand[][2], char *suit[], char *face[]);

void pair(unsigned int hand[][2], char *suit[], char *face[]);

void threeOfKind(unsigned int hand[][2], char *suit[], char *face[]);

void fourOfKind(unsigned int hand[][2], char *suit[], char *face[]);

void straightHand(unsigned int hand[][2], char *suit[], char *face[]);

void flushHand(unsigned int hand[][2], char *suit[], char *face[]);

int main()

{

char *suit[SUITS] = { "Hearts", "Diamonds", "Clubs", "Spades" };

char *face[FACES] = { "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",

"Ten", "Jack", "Queen", "King" };

unsigned int deck[SUITS][FACES]; //represents deck of cards

unsigned int hand[5][2]; //represents hand

size_t row, column; //loop counters

//loop through rows of deck

for (row = 0; row < SUITS; ++row)

{

//loop through columns of deck for current row

for (column = 0; column < FACES; ++column)

{

deck[row][column] = 0; // initialize slot of deck to 0

} //end inner for

} //End outer for

srand(time(NULL)); // seed random number generator

//Shuffle the deck and deal a 5-card hand

shuffle(deck);

deal(deck, hand, suit, face);

//determine the hands poker value

pair(hand, suit, face);

threeOfKind(hand, suit, face);

fourOfKind(hand, suit, face);

straightHand(hand, suit, face);

flushHand(hand, suit, face);

}// end function main

//shuffles the deck

void shuffle(unsigned int deck[][FACES])

{

size_t row; //represents suit value of card

size_t column; // represents face value of card

unsigned int card; // loop counter

// for each of the 52 cards, choose a slot of the deck randomly

for (card = 1; card <= CARDS; ++card)

{

do // choose a new random location until unoccupied slot is found

{

row = rand() % SUITS; // randomly select row

column = rand() % FACES; //randomly select column

} while (deck[row][column] != 0); //end do ... while

//place card number in chosen slot of deck

deck[row][column] = card;

}// end for

}// end function shuffle

//deals a poker hand

void deal(unsigned int deck[][FACES], unsigned int hand[][2], char *suit[], char *face[])

{

unsigned int r = 0; //counter for position in the hand

size_t card, row, column; //loop counters

puts("The hand is: ");

//loop to distribute cards

for (card = 1; card < 6; ++card)

for (row = 0; row < SUITS; ++row)

for (column = 0; column < FACES; ++column)

if (deck[row][column] == card)

{

hand[r][0] = row;

hand[r][1] = column;

printf("%5s of %-8s ", face[column], suit[row]);

++r;

}//end if

puts(" ");

} //end function deal

//determines if there are any pairs in the hand

void pair(unsigned int hand[][2], char *suit[], char *face[])

{

//counter that records how many cards of each rank are in the hand

unsigned int counter[FACES] = { 0 };

size_t r, p; // loop counters

//record how many cards of each rank are in the hand

for (r = 0; r < 5; ++r)

++counter[hand[r][1]];

//print result if there is a pair

for (p = 0; p < FACES; ++p)

if (counter[p] == 2)

printf("The hand contains a pair of %ss. ", face[p]);

}//end function pair

//Determine if there is a three of a kind in the hand

void threeOfKind(unsigned int hand[][2], char *suit[], char *face[])

{

//Counter that records how many cards of each rank are in the hand

unsigned int counter[FACES] = { 0 };

size_t r, t; // loop counters

//record how many cards of each rank are in the hand

for (r = 0; r < 5; ++r)

++counter[hand[r][1]];

//print results if there is a three of a kind

for (t = 0; t < FACES; ++t)

if (counter[t] == 3)

printf("The hand contains three %ss. ", face[t]);

} // end function threeOfKind

//determines if there is a four of a kind in the hand

void fourOfKind(unsigned int hand[][2], char *suit[], char *face[])

{

//counter that records how many cards of each rank are in the hand

unsigned int counter[FACES] = { 0 };

size_t r, k; // loop counters

//record how many cards of each rank are in the hand

for (r = 0; r < 5; ++r)

++counter[hand[r][1]];

//print result if there is a pair

for (k = 0; k < FACES; ++k)

if (counter[k] == 4)

printf("The hand contains four %ss. ", face[k]);

} // end function fourOfKind

// Determines if there is a straight in the hand

void straightHand(unsigned int hand[][2], char *suit[], char *face[])

{

unsigned int s[5] = { 0 }; //array that holds a copy of the hand

unsigned int temp; // temporary integer

size_t r, pass, comp; // loop counters

//copy column locations to sort

for (r = 0; r < 5; ++r)

s[r] = hand[r][1];

//bubble sort column locations

for (pass = 1; pass < 5; ++pass)

for (comp = 0; comp < 4; ++comp)

if (s[comp] > s[comp + 1])

{

temp = s[comp];

s[comp] = s[comp + 1];

s[comp + 1] = temp;

}//end if

//check if sorted column are straight

if (s[4] - 1 == s[3] && s[3] - 1 == s[2]

&& s[2] - 1 == s[1] && s[1] - 1 == s[0])

{

printf("The hand contains a straight from %s to %s. ", face[s[0]], face[s[4]]);

}// end if

}//end funtion straightHand

//determines if there is a flush in the hand

void flushHand(unsigned int hand[][2], char *suit[], char *face[])

{

//counter that records how many cards of each suit are in a hand

unsigned int count[SUITS] = { 0 };

size_t r, f; // loop counters

//record how many cards of each suit are in the hand

for (r = 0; r < 5; ++r)

++count[hand[r][0]];

for (f = 0; f < SUITS; ++f)

if (count[f] == 5)

printf("The hand contains a flush of %ss. ", suit[f]);

}// end function flushHand

Explanation / Answer

Do you mean in Assembly code. If you want the assembly code then here it is.

main:

stp x29, x30, [sp, -416]!

add x29, sp, 0

add x0, x29, 368

adrp x1, .LC19

add x1, x1, :lo12:.LC19

ld1 {v0.16b - v1.16b}, [x1]

st1 {v0.16b - v1.16b}, [x0]

adrp x0, .LC20

add x1, x0, :lo12:.LC20

add x0, x29, 264

mov x3, x1

mov x1, 104

mov x2, x1

mov x1, x3

bl memcpy

str xzr, [x29, 408]

.L5:

ldr x0, [x29, 408]

cmp x0, 3

bhi .L2

str xzr, [x29, 400]

.L4:

ldr x0, [x29, 400]

cmp x0, 12

bhi .L3

ldr x1, [x29, 408]

mov x0, x1

lsl x0, x0, 1

add x0, x0, x1

lsl x0, x0, 2

add x0, x0, x1

ldr x1, [x29, 400]

add x0, x0, x1

lsl x0, x0, 2

add x1, x29, 56

str wzr, [x1, x0]

ldr x0, [x29, 400]

add x0, x0, 1

str x0, [x29, 400]

b .L4

.L3:

ldr x0, [x29, 408]

add x0, x0, 1

str x0, [x29, 408]

b .L5

.L2:

mov x0, 0

bl time

bl srand

add x0, x29, 56

bl shuffle(unsigned int (*) [13])

add x3, x29, 264

add x2, x29, 368

add x1, x29, 16

add x0, x29, 56

bl deal(unsigned int (*) [13], unsigned int (*) [2], char**, char**)

add x2, x29, 264

add x1, x29, 368

add x0, x29, 16

bl pair(unsigned int (*) [2], char**, char**)

add x2, x29, 264

add x1, x29, 368

add x0, x29, 16

bl threeOfKind(unsigned int (*) [2], char**, char**)

add x2, x29, 264

add x1, x29, 368

add x0, x29, 16

bl fourOfKind(unsigned int (*) [2], char**, char**)

add x2, x29, 264

add x1, x29, 368

add x0, x29, 16

bl straightHand(unsigned int (*) [2], char**, char**)

add x2, x29, 264

add x1, x29, 368

add x0, x29, 16

bl flushHand(unsigned int (*) [2], char**, char**)

mov w0, 0

ldp x29, x30, [sp], 416

ret

.LC19:

.string "Ace"

.string "Deuce"

.string "Three"

.string "Four"

.string "Five"

.string "Six"

.string "Seven"

.string "Eight"

.string "Nine"

.string "Ten"

.string "Jack"

.string "Queen"

.string "King"

.LC20:

shuffle(unsigned int (*) [13]):

stp x29, x30, [sp, -64]!

add x29, sp, 0

str x0, [x29, 24]

mov w0, 1

str w0, [x29, 60]

.L11:

ldr w0, [x29, 60]

cmp w0, 52

bhi .L12

.L10:

bl rand

negs w1, w0

and w0, w0, 3

and w1, w1, 3

csneg w0, w0, w1, mi

sxtw x0, w0

str x0, [x29, 48]

bl rand

mov w1, w0

mov w0, 60495

movk w0, 0x4ec4, lsl 16

smull x0, w1, w0

lsr x0, x0, 32

asr w2, w0, 2

asr w0, w1, 31

sub w0, w2, w0

mov w2, 13

mul w0, w0, w2

sub w0, w1, w0

sxtw x0, w0

str x0, [x29, 40]

ldr x1, [x29, 48]

mov x0, x1

lsl x0, x0, 1

add x0, x0, x1

lsl x0, x0, 2

add x0, x0, x1

lsl x0, x0, 2

mov x1, x0

ldr x0, [x29, 24]

add x0, x0, x1

ldr x1, [x29, 40]

ldr w0, [x0, x1, lsl 2]

cmp w0, 0

beq .L9

b .L10

.L9:

ldr x1, [x29, 48]

mov x0, x1

lsl x0, x0, 1

add x0, x0, x1

lsl x0, x0, 2

add x0, x0, x1

lsl x0, x0, 2

mov x1, x0

ldr x0, [x29, 24]

add x0, x0, x1

ldr x1, [x29, 40]

ldr w2, [x29, 60]

str w2, [x0, x1, lsl 2]

ldr w0, [x29, 60]

add w0, w0, 1

str w0, [x29, 60]

b .L11

.L12:

nop

ldp x29, x30, [sp], 64

ret

.LC21:

.string "The hand is: "

.LC22:

.string "%5s of %-8s "

.LC23:

.string " "

deal(unsigned int (*) [13], unsigned int (*) [2], char**, char**):

stp x29, x30, [sp, -80]!

add x29, sp, 0

str x0, [x29, 40]

str x1, [x29, 32]

str x2, [x29, 24]

str x3, [x29, 16]

str wzr, [x29, 76]

adrp x0, .LC21

add x0, x0, :lo12:.LC21

bl puts

mov x0, 1

str x0, [x29, 64]

.L20:

ldr x0, [x29, 64]

cmp x0, 5

bhi .L14

str xzr, [x29, 56]

.L19:

ldr x0, [x29, 56]

cmp x0, 3

bhi .L15

str xzr, [x29, 48]

.L18:

ldr x0, [x29, 48]

cmp x0, 12

bhi .L16

ldr x1, [x29, 56]

mov x0, x1

lsl x0, x0, 1

add x0, x0, x1

lsl x0, x0, 2

add x0, x0, x1

lsl x0, x0, 2

mov x1, x0

ldr x0, [x29, 40]

add x0, x0, x1

ldr x1, [x29, 48]

ldr w0, [x0, x1, lsl 2]

uxtw x1, w0

ldr x0, [x29, 64]

cmp x1, x0

bne .L17

ldr w0, [x29, 76]

lsl x0, x0, 3

ldr x1, [x29, 32]

add x0, x1, x0

ldr x1, [x29, 56]

str w1, [x0]

ldr w0, [x29, 76]

lsl x0, x0, 3

ldr x1, [x29, 32]

add x0, x1, x0

ldr x1, [x29, 48]

str w1, [x0, 4]

ldr x0, [x29, 48]

lsl x0, x0, 3

ldr x1, [x29, 16]

add x0, x1, x0

ldr x3, [x0]

ldr x0, [x29, 56]

lsl x0, x0, 3

ldr x1, [x29, 24]

add x0, x1, x0

ldr x1, [x0]

adrp x0, .LC22

add x0, x0, :lo12:.LC22

mov x2, x1

mov x1, x3

bl printf

ldr w0, [x29, 76]

add w0, w0, 1

str w0, [x29, 76]

.L17:

ldr x0, [x29, 48]

add x0, x0, 1

str x0, [x29, 48]

b .L18

.L16:

ldr x0, [x29, 56]

add x0, x0, 1

str x0, [x29, 56]

b .L19

.L15:

ldr x0, [x29, 64]

add x0, x0, 1

str x0, [x29, 64]

b .L20

.L14:

adrp x0, .LC23

add x0, x0, :lo12:.LC23

bl puts

nop

ldp x29, x30, [sp], 80

ret

.LC24:

.string "The hand contains a pair of %ss. "

pair(unsigned int (*) [2], char**, char**):

stp x29, x30, [sp, -128]!

add x29, sp, 0

str x0, [x29, 40]

str x1, [x29, 32]

str x2, [x29, 24]

add x0, x29, 56

stp xzr, xzr, [x0]

add x0, x29, 72

stp xzr, xzr, [x0]

add x0, x29, 88

stp xzr, xzr, [x0]

str wzr, [x29, 104]

str xzr, [x29, 120]

.L23:

ldr x0, [x29, 120]

cmp x0, 4

bhi .L22

ldr x0, [x29, 120]

lsl x0, x0, 3

ldr x1, [x29, 40]

add x0, x1, x0

ldr w3, [x0, 4]

uxtw x0, w3

lsl x0, x0, 2

add x1, x29, 56

ldr w0, [x1, x0]

add w2, w0, 1

uxtw x0, w3

lsl x0, x0, 2

add x1, x29, 56

str w2, [x1, x0]

ldr x0, [x29, 120]

add x0, x0, 1

str x0, [x29, 120]

b .L23

.L22:

str xzr, [x29, 112]

.L26:

ldr x0, [x29, 112]

cmp x0, 12

bhi .L27

ldr x0, [x29, 112]

lsl x0, x0, 2

add x1, x29, 56

ldr w0, [x1, x0]

cmp w0, 2

bne .L25

ldr x0, [x29, 112]

lsl x0, x0, 3

ldr x1, [x29, 24]

add x0, x1, x0

ldr x1, [x0]

adrp x0, .LC24

add x0, x0, :lo12:.LC24

bl printf

.L25:

ldr x0, [x29, 112]

add x0, x0, 1

str x0, [x29, 112]

b .L26

.L27:

nop

ldp x29, x30, [sp], 128

ret

.LC25:

.string "The hand contains three %ss. "

threeOfKind(unsigned int (*) [2], char**, char**):

stp x29, x30, [sp, -128]!

add x29, sp, 0

str x0, [x29, 40]

str x1, [x29, 32]

str x2, [x29, 24]

add x0, x29, 56

stp xzr, xzr, [x0]

add x0, x29, 72

stp xzr, xzr, [x0]

add x0, x29, 88

stp xzr, xzr, [x0]

str wzr, [x29, 104]

str xzr, [x29, 120]

.L30:

ldr x0, [x29, 120]

cmp x0, 4

bhi .L29

ldr x0, [x29, 120]

lsl x0, x0, 3

ldr x1, [x29, 40]

add x0, x1, x0

ldr w3, [x0, 4]

uxtw x0, w3

lsl x0, x0, 2

add x1, x29, 56

ldr w0, [x1, x0]

add w2, w0, 1

uxtw x0, w3

lsl x0, x0, 2

add x1, x29, 56

str w2, [x1, x0]

ldr x0, [x29, 120]

add x0, x0, 1

str x0, [x29, 120]

b .L30

.L29:

str xzr, [x29, 112]

.L33:

ldr x0, [x29, 112]

cmp x0, 12

bhi .L34

ldr x0, [x29, 112]

lsl x0, x0, 2

add x1, x29, 56

ldr w0, [x1, x0]

cmp w0, 3

bne .L32

ldr x0, [x29, 112]

lsl x0, x0, 3

ldr x1, [x29, 24]

add x0, x1, x0

ldr x1, [x0]

adrp x0, .LC25

add x0, x0, :lo12:.LC25

bl printf

.L32:

ldr x0, [x29, 112]

add x0, x0, 1

str x0, [x29, 112]

b .L33

.L34:

nop

ldp x29, x30, [sp], 128

ret

.LC26:

.string "The hand contains four %ss. "

fourOfKind(unsigned int (*) [2], char**, char**):

stp x29, x30, [sp, -128]!

add x29, sp, 0

str x0, [x29, 40]

str x1, [x29, 32]

str x2, [x29, 24]

add x0, x29, 56

stp xzr, xzr, [x0]

add x0, x29, 72

stp xzr, xzr, [x0]

add x0, x29, 88

stp xzr, xzr, [x0]

str wzr, [x29, 104]

str xzr, [x29, 120]

.L37:

ldr x0, [x29, 120]

cmp x0, 4

bhi .L36

ldr x0, [x29, 120]

lsl x0, x0, 3

ldr x1, [x29, 40]

add x0, x1, x0

ldr w3, [x0, 4]

uxtw x0, w3

lsl x0, x0, 2

add x1, x29, 56

ldr w0, [x1, x0]

add w2, w0, 1

uxtw x0, w3

lsl x0, x0, 2

add x1, x29, 56

str w2, [x1, x0]

ldr x0, [x29, 120]

add x0, x0, 1

str x0, [x29, 120]

b .L37

.L36:

str xzr, [x29, 112]

.L40:

ldr x0, [x29, 112]

cmp x0, 12

bhi .L41

ldr x0, [x29, 112]

lsl x0, x0, 2

add x1, x29, 56

ldr w0, [x1, x0]

cmp w0, 4

bne .L39

ldr x0, [x29, 112]

lsl x0, x0, 3

ldr x1, [x29, 24]

add x0, x1, x0

ldr x1, [x0]

adrp x0, .LC26

add x0, x0, :lo12:.LC26

bl printf

.L39:

ldr x0, [x29, 112]

add x0, x0, 1

str x0, [x29, 112]

b .L40

.L41:

nop

ldp x29, x30, [sp], 128

ret

.LC27:

.string "The hand contains a straight from %s to %s. "

straightHand(unsigned int (*) [2], char**, char**):

stp x29, x30, [sp, -96]!

add x29, sp, 0

str x0, [x29, 40]

str x1, [x29, 32]

str x2, [x29, 24]

stp xzr, xzr, [x29, 48]

str wzr, [x29, 64]

str xzr, [x29, 88]

.L44:

ldr x0, [x29, 88]

cmp x0, 4

bhi .L43

ldr x0, [x29, 88]

lsl x0, x0, 3

ldr x1, [x29, 40]

add x0, x1, x0

ldr w2, [x0, 4]

ldr x0, [x29, 88]

lsl x0, x0, 2

add x1, x29, 48

str w2, [x1, x0]

ldr x0, [x29, 88]

add x0, x0, 1

str x0, [x29, 88]

b .L44

.L43:

mov x0, 1

str x0, [x29, 80]

.L49:

ldr x0, [x29, 80]

cmp x0, 4

bhi .L45

str xzr, [x29, 72]

.L48:

ldr x0, [x29, 72]

cmp x0, 3

bhi .L46

ldr x0, [x29, 72]

lsl x0, x0, 2

add x1, x29, 48

ldr w1, [x1, x0]

ldr x0, [x29, 72]

add x0, x0, 1

lsl x0, x0, 2

add x2, x29, 48

ldr w0, [x2, x0]

cmp w1, w0

bls .L47

ldr x0, [x29, 72]

lsl x0, x0, 2

add x1, x29, 48

ldr w0, [x1, x0]

str w0, [x29, 68]

ldr x0, [x29, 72]

add x0, x0, 1

lsl x0, x0, 2

add x1, x29, 48

ldr w2, [x1, x0]

ldr x0, [x29, 72]

lsl x0, x0, 2

add x1, x29, 48

str w2, [x1, x0]

ldr x0, [x29, 72]

add x0, x0, 1

lsl x0, x0, 2

add x1, x29, 48

ldr w2, [x29, 68]

str w2, [x1, x0]

.L47:

ldr x0, [x29, 72]

add x0, x0, 1

str x0, [x29, 72]

b .L48

.L46:

ldr x0, [x29, 80]

add x0, x0, 1

str x0, [x29, 80]

b .L49

.L45:

ldr w0, [x29, 64]

sub w1, w0, #1

ldr w0, [x29, 60]

cmp w1, w0

bne .L51

ldr w0, [x29, 60]

sub w1, w0, #1

ldr w0, [x29, 56]

cmp w1, w0

bne .L51

ldr w0, [x29, 56]

sub w1, w0, #1

ldr w0, [x29, 52]

cmp w1, w0

bne .L51

ldr w0, [x29, 52]

sub w1, w0, #1

ldr w0, [x29, 48]

cmp w1, w0

bne .L51

ldr w0, [x29, 48]

uxtw x0, w0

lsl x0, x0, 3

ldr x1, [x29, 24]

add x0, x1, x0

ldr x3, [x0]

ldr w0, [x29, 64]

uxtw x0, w0

lsl x0, x0, 3

ldr x1, [x29, 24]

add x0, x1, x0

ldr x1, [x0]

adrp x0, .LC27

add x0, x0, :lo12:.LC27

mov x2, x1

mov x1, x3

bl printf

.L51:

nop

ldp x29, x30, [sp], 96

ret

.LC28:

.string "The hand contains a flush of %ss. "

flushHand(unsigned int (*) [2], char**, char**):

stp x29, x30, [sp, -80]!

add x29, sp, 0

str x0, [x29, 40]

str x1, [x29, 32]

str x2, [x29, 24]

stp xzr, xzr, [x29, 48]

str xzr, [x29, 72]

.L54:

ldr x0, [x29, 72]

cmp x0, 4

bhi .L53

ldr x0, [x29, 72]

lsl x0, x0, 3

ldr x1, [x29, 40]

add x0, x1, x0

ldr w3, [x0]

uxtw x0, w3

lsl x0, x0, 2

add x1, x29, 48

ldr w0, [x1, x0]

add w2, w0, 1

uxtw x0, w3

lsl x0, x0, 2

add x1, x29, 48

str w2, [x1, x0]

ldr x0, [x29, 72]

add x0, x0, 1

str x0, [x29, 72]

b .L54

.L53:

str xzr, [x29, 64]

.L57:

ldr x0, [x29, 64]

cmp x0, 3

bhi .L58

ldr x0, [x29, 64]

lsl x0, x0, 2

add x1, x29, 48

ldr w0, [x1, x0]

cmp w0, 5

bne .L56

ldr x0, [x29, 64]

lsl x0, x0, 3

ldr x1, [x29, 32]

add x0, x1, x0

ldr x1, [x0]

adrp x0, .LC28

add x0, x0, :lo12:.LC28

bl printf

.L56:

ldr x0, [x29, 64]

add x0, x0, 1

str x0, [x29, 64]

b .L57

.L58:

nop

ldp x29, x30, [sp], 80

ret

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