I need pseudocode for this assembly code: .def __main; .scl 2; .type 32; .endef
ID: 3576818 • Letter: I
Question
I need pseudocode for this assembly code:
.def __main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.LC0:
.ascii "r"
.LC1:
.ascii "Hangman Words.txt"
.LC2:
.ascii "Unable To Read File"
.LC3:
.ascii "%s"
.LC4:
.ascii "
New Turn....
Hangman Word:"
.LC5:
.ascii "Enter a guess letter:"
.LC6:
.ascii "letterEntered:%c
"
.LC7:
.ascii "Sorry, wrong guess"
.LC8:
.ascii "Already Guessed!!"
.LC9:
.ascii "Correct guess :)"
.align 8
.LC10:
.ascii "
Oops you lose, the word was: %s
"
.align 8
.LC11:
.ascii "
CONGRATS, YOU GOT THE WORD!!! :)"
.text
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
main:
pushq %rbp
.seh_pushreg %rbp
movl $8400, %eax
call ___chkstk_ms
subq %rax, %rsp
.seh_stackalloc 8400
leaq 128(%rsp), %rbp
.seh_setframe %rbp, 128
.seh_endprologue
call __main
movl $0, %ecx
call time
movl %eax, %ecx
call srand
movl $0, 8268(%rbp)
leaq .LC0(%rip), %rdx
leaq .LC1(%rip), %rcx
call fopen
movq %rax, 8240(%rbp)
cmpq $0, 8240(%rbp)
jne .L4
leaq .LC2(%rip), %rcx
call puts
movl $0, %eax
jmp .L24
.L5:
leaq 32(%rbp), %rax
movl 8268(%rbp), %edx
movslq %edx, %rdx
salq $4, %rdx
addq %rax, %rdx
leaq -32(%rbp), %rax
movq %rdx, %r8
leaq .LC3(%rip), %rdx
movq %rax, %rcx
call sscanf
addl $1, 8268(%rbp)
.L4:
movq 8240(%rbp), %rdx
leaq -32(%rbp), %rax
movq %rdx, %r8
movl $63, %edx
movq %rax, %rcx
call fgets
testq %rax, %rax
jne .L5
movq 8240(%rbp), %rax
movq %rax, %rcx
call fclose
call rand
cltd
idivl 8268(%rbp)
movl %edx, 8236(%rbp)
movl $5, 8264(%rbp)
movl $0, 8260(%rbp)
movl $0, 8232(%rbp)
leaq 32(%rbp), %rax
movl 8236(%rbp), %edx
movslq %edx, %rdx
salq $4, %rdx
addq %rdx, %rax
movq %rax, %rcx
call strlen
movl %eax, 8228(%rbp)
movq $0, -80(%rbp)
movq $0, -72(%rbp)
movq $0, -64(%rbp)
movq $0, -56(%rbp)
movq $0, -48(%rbp)
movl $0, 8256(%rbp)
movl $0, 8252(%rbp)
jmp .L6
.L21:
leaq .LC4(%rip), %rcx
call printf
movl $0, 8256(%rbp)
jmp .L7
.L10:
movl 8256(%rbp), %eax
cltq
movl -80(%rbp,%rax,4), %eax
cmpl $1, %eax
jne .L8
movl 8256(%rbp), %eax
cltq
movl 8236(%rbp), %edx
movslq %edx, %rdx
salq $4, %rdx
leaq 8272(%rbp), %rcx
addq %rcx, %rdx
addq %rdx, %rax
subq $8240, %rax
movzbl (%rax), %eax
movsbl %al, %eax
movl %eax, %ecx
call putchar
jmp .L9
.L8:
movl $45, %ecx
call putchar
.L9:
addl $1, 8256(%rbp)
.L7:
movl 8256(%rbp), %eax
cmpl 8228(%rbp), %eax
jl .L10
movl $10, %ecx
call putchar
leaq .LC5(%rip), %rcx
call printf
movq __imp___iob_func(%rip), %rax
call *%rax
movq %rax, %rdx
leaq -96(%rbp), %rax
movq %rdx, %r8
movl $16, %edx
movq %rax, %rcx
call fgets
movzbl -96(%rbp), %eax
movb %al, 8227(%rbp)
movl $0, 8252(%rbp)
movsbl 8227(%rbp), %eax
movl %eax, %edx
leaq .LC6(%rip), %rcx
call printf
movl 8260(%rbp), %eax
movl %eax, 8232(%rbp)
movl $0, 8256(%rbp)
jmp .L11
.L16:
movl 8256(%rbp), %eax
cltq
movl -80(%rbp,%rax,4), %eax
cmpl $1, %eax
jne .L12
movl 8256(%rbp), %eax
cltq
movl 8236(%rbp), %edx
movslq %edx, %rdx
salq $4, %rdx
leaq 8272(%rbp), %rcx
addq %rcx, %rdx
addq %rdx, %rax
subq $8240, %rax
movzbl (%rax), %eax
cmpb 8227(%rbp), %al
jne .L25
movl $1, 8252(%rbp)
jmp .L14
.L12:
movl 8256(%rbp), %eax
cltq
movl 8236(%rbp), %edx
movslq %edx, %rdx
salq $4, %rdx
leaq 8272(%rbp), %rcx
addq %rcx, %rdx
addq %rdx, %rax
subq $8240, %rax
movzbl (%rax), %eax
cmpb 8227(%rbp), %al
jne .L15
movl 8256(%rbp), %eax
cltq
movl $1, -80(%rbp,%rax,4)
addl $1, 8260(%rbp)
jmp .L15
.L25:
nop
.L15:
addl $1, 8256(%rbp)
.L11:
movl 8256(%rbp), %eax
cmpl 8228(%rbp), %eax
jl .L16
.L14:
movl 8232(%rbp), %eax
cmpl 8260(%rbp), %eax
jne .L17
cmpl $0, 8252(%rbp)
jne .L17
subl $1, 8264(%rbp)
leaq .LC7(%rip), %rcx
call puts
cmpl $0, 8264(%rbp)
je .L26
jmp .L6
.L17:
cmpl $1, 8252(%rbp)
jne .L20
leaq .LC8(%rip), %rcx
call puts
jmp .L6
.L20:
leaq .LC9(%rip), %rcx
call puts
.L6:
movl 8260(%rbp), %eax
cmpl 8228(%rbp), %eax
jl .L21
jmp .L19
.L26:
nop
.L19:
cmpl $0, 8264(%rbp)
jne .L22
leaq 32(%rbp), %rax
movl 8236(%rbp), %edx
movslq %edx, %rdx
salq $4, %rdx
addq %rdx, %rax
movq %rax, %rdx
leaq .LC10(%rip), %rcx
call printf
jmp .L23
.L22:
leaq .LC11(%rip), %rcx
call puts
.L23:
movl $0, %eax
.L24:
addq $8400, %rsp
popq %rbp
ret
.seh_endproc
.ident "GCC: (tdm64-1) 5.1.0"
.def time; .scl 2; .type 32; .endef
.def srand; .scl 2; .type 32; .endef
.def fopen; .scl 2; .type 32; .endef
.def puts; .scl 2; .type 32; .endef
.def sscanf; .scl 2; .type 32; .endef
.def fgets; .scl 2; .type 32; .endef
.def fclose; .scl 2; .type 32; .endef
.def rand; .scl 2; .type 32; .endef
.def strlen; .scl 2; .type 32; .endef
.def printf; .scl 2; .type 32; .endef
.def putchar; .scl 2; .type 32; .endef
Explanation / Answer
pseudo code:
MAIN
Open the text file "Hangman Words.txt"
IF file is not opened
print "unable to read file"
ENDIF
ELSE
print "New Turn.... Hangman Word:"
intialize count = 0;
for (x=0; x<letter.length; x++) //letter.length Guesses
{
print "Enter a guess letter:"
Read letter
print "letterEntered:",letter
//bool found = false;
for (k=0; k<word.length();k++) //Compare you guess to the word
{
if (letter == word[k])
{
print "correct Guess:)"
letters[k] = guess;
found = true;
count++;
}
else
print "sorry,wrong guess"
}
if(count == word.length())
{
cout << "Congrats, you got the word!!!:)" << endl;
break;
}
if (!found) //You lose when you get 6 wrong letters
{
wrong++;
if (wrong==6)
{
print "oops you loose, The word was:"
break;
}
}
ENDELSE
ENDMAIN