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

Write down the steps before you start with the Simulator and editor You don\'t n

ID: 2268256 • Letter: W

Question

Write down the steps before you start with the Simulator and editor You don't need to submit these but will help greatly in completing the Start your program at x3000 so that it will be easier for me to grade it. Each program must include a header comment that has your name(s) and a brief description of the program. Make sure to comment each line of code in the case of machine code and have adequate comments in case of assembly code. You will be graded on comments 1. (7 Points) Write a machine language program for the LC3. It should print out the letters: ABCD. XYzzYX... .DCBA. That's a total of 26 *2 = 52 letters. You must use one or two loops. Name your file PrintLetters.bin. Machine code compiles 3 Points Works correctly-2 Points Commented adequately - 2 Points Named incorrectly-(1 Point)

Explanation / Answer

program in c-language

#include<stdio.h>

int main()

{

int guss=1;

int num;

printf("Guss a number ");

scanf("%c",&num);

while(num!='6')

{

if(num<(char)48 || num>(char)57)

{

printf("Invalid input ");

}

else if(num>(char)54)

{

printf("Too big ");

}

else

{

printf("Too small ");

}

printf("Guss again ");

scanf(" %c",&num);

guss++;

}

printf("Correct! You took %d gusses",guss);

return 0;

}

Equivalent Assembly Code

.file   1 ""

        .section .mdebug.abi32

        .previous

        .nan    legacy

        .module fp=32

        .module nooddspreg

        .abicalls

        .rdata

        .align 2

$LC0:

        .ascii "Guss a number"

        .align 2

$LC1:

        .ascii "%c"

        .align 2

$LC2:

        .ascii "Invalid input"

        .align 2

$LC3:

        .ascii "Too big"

        .align 2

$LC4:

        .ascii "Too small"

        .align 2

$LC5:

        .ascii "Guss again"

        .align 2

$LC6:

        .ascii " %c"

        .align 2

$LC7:

        .ascii "Correct! You took %d gusses"

        .text

        .align 2

        .globl main

        .set    nomips16

        .set    nomicromips

        .ent    main

        .type   main, @function

main:

        .frame $fp,40,$31              # vars= 8, regs= 2/0, args= 16, gp= 8

        .mask   0xc0000000,-4

        .fmask 0x00000000,0

        .set    noreorder

        .cpload $25

        .set    nomacro

        addiu   $sp,$sp,-40

        sw      $31,36($sp)

        sw      $fp,32($sp)

        move    $fp,$sp

        .cprestore      16

        movz    $31,$31,$0

        li      $2,1                    # 0x1

        sw      $2,24($fp)

        lw      $2,%got($LC0)($28)

        nop

        addiu   $4,$2,%lo($LC0)

        lw      $2,%call16(puts)($28)

        nop

        move    $25,$2

        .reloc 1f,R_MIPS_JALR,puts

1:      jalr    $25

        nop

        lw      $28,16($fp)

        addiu   $2,$fp,28

        move    $5,$2

        lw      $2,%got($LC1)($28)

        nop

        addiu   $4,$2,%lo($LC1)

        lw      $2,%call16(__isoc99_scanf)($28)

        nop

        move    $25,$2

        .reloc 1f,R_MIPS_JALR,__isoc99_scanf

1:      jalr    $25

        nop

        lw      $28,16($fp)

        b       $L2

        nop

$L7:

        lw      $2,28($fp)

        nop

        slt     $2,$2,48

        bne     $2,$0,$L3

        nop

        lw      $2,28($fp)

        nop

        slt     $2,$2,58

        bne     $2,$0,$L4

        nop

$L3:

        lw      $2,%got($LC2)($28)

        nop

        addiu   $4,$2,%lo($LC2)

        lw      $2,%call16(puts)($28)

        nop

        move    $25,$2

        .reloc 1f,R_MIPS_JALR,puts

1:      jalr    $25

        nop

        lw      $28,16($fp)

       b       $L5

        nop

$L4:

        lw      $2,28($fp)

        nop

        slt     $2,$2,55

        bne     $2,$0,$L6

        nop

        lw      $2,%got($LC3)($28)

        nop

        addiu   $4,$2,%lo($LC3)

        lw      $2,%call16(puts)($28)

        nop

        move    $25,$2

        .reloc 1f,R_MIPS_JALR,puts

1:      jalr    $25

        nop

        lw      $28,16($fp)

        b       $L5

        nop

$L6:

        lw      $2,%got($LC4)($28)

        nop

        addiu   $4,$2,%lo($LC4)

       lw      $2,%call16(puts)($28)

        nop

        move    $25,$2

        .reloc 1f,R_MIPS_JALR,puts

1:      jalr    $25

        nop

        lw      $28,16($fp)

        nop

$L5:

        lw      $2,%got($LC5)($28)

        nop

        addiu   $4,$2,%lo($LC5)

        lw      $2,%call16(puts)($28)

        nop

        move    $25,$2

        .reloc 1f,R_MIPS_JALR,puts

1:      jalr    $25

        nop

        lw      $28,16($fp)

        addiu   $2,$fp,28

        move    $5,$2

        lw      $2,%got($LC6)($28)

        nop

        addiu   $4,$2,%lo($LC6)

        lw      $2,%call16(__isoc99_scanf)($28)

        nop

        move    $25,$2

        .reloc 1f,R_MIPS_JALR,__isoc99_scanf

1:      jalr    $25

        nop

        lw      $28,16($fp)

        lw      $2,24($fp)

        nop

        addiu   $2,$2,1

        sw      $2,24($fp)

$L2:

        lw      $3,28($fp)

        li      $2,54                   # 0x36

        bne     $3,$2,$L7

        nop

        lw      $5,24($fp)

        lw      $2,%got($LC7)($28)

        nop

        addiu   $4,$2,%lo($LC7)

        lw      $2,%call16(printf)($28)

        nop

        move    $25,$2

        .reloc 1f,R_MIPS_JALR,printf

1:      jalr    $25

        nop

        lw      $28,16($fp)

        move    $2,$0

        move    $sp,$fp

        lw      $31,36($sp)

        lw      $fp,32($sp)

        addiu   $sp,$sp,40

        j       $31

        nop

        .set    macro

        .set    reorder

        .end    main

        .size   main, .-main

        .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"

Samle Output:-

Guss a number

8

Too big

Guss again

4

Too small

Guss again

a

Invalid input

Guss again

b

Invalid input

Guss again

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