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

Create an HLA Assembly language program that prompts for a single integer value

ID: 3913699 • Letter: C

Question

Create an HLA Assembly language program that prompts for a single integer value from the user and prints an boxy pattern like the one shown below. If the number is negative, don't print anything at all.

Here are some example program dialogues to guide your efforts:

Feed Me: 5
55555
5   5
5   5
5   5
55555

Feed Me: -6

Feed Me: 3
333
3 3
333

In an effort to help you focus on building an Assembly program, I’d like to offer you the following C statements matches the program specifications stated above. If you like, use them as the basis for building your Assembly program.

SAMPLE C CODE:
------------------------

int i, n, j;
printf( "Feed Me:" );
scanf( "%d", &n );

for (i=1;

i<=n; i++) {
   if (i == 1 || i == n) { // first or last row
      for (j = 1; j <= n; j++) {
          printf( "%d", n );
      }
      printf( " " );
   }
   else { // internal rows of the box
      printf( "%d", n );
      for (j = 1; j <= n-2; j++) {
          printf( " " );
      }
      printf( "%d", n );
      printf( " " );
   }

}

Explanation / Answer

For the c program given for referrence the assembly languague will be :

.LC0:
        .string "Feed Me:"
.LC1:
        .string "%d"
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     edi, OFFSET FLAT:.LC0
        mov     eax, 0
        call    printf
        lea     rax, [rbp-12]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    scanf
        mov     DWORD PTR [rbp-4], 1
.L10:
        mov     eax, DWORD PTR [rbp-12]
        cmp     DWORD PTR [rbp-4], eax
        jg      .L2
        cmp     DWORD PTR [rbp-4], 1
        je      .L3
        mov     eax, DWORD PTR [rbp-12]
        cmp     DWORD PTR [rbp-4], eax
        jne     .L4
.L3:
        mov     DWORD PTR [rbp-8], 1
.L6:
        mov     eax, DWORD PTR [rbp-12]
        cmp     DWORD PTR [rbp-8], eax
        jg      .L5
        mov     eax, DWORD PTR [rbp-12]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    printf
        add     DWORD PTR [rbp-8], 1
        jmp     .L6
.L5:
        mov     edi, 10
        call    putchar
        jmp     .L7
.L4:
        mov     eax, DWORD PTR [rbp-12]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    printf
        mov     DWORD PTR [rbp-8], 1
.L9:
        mov     eax, DWORD PTR [rbp-12]
        sub     eax, 1
        cmp     DWORD PTR [rbp-8], eax
        jge     .L8
        mov     edi, 32
        call    putchar
        add     DWORD PTR [rbp-8], 1
        jmp     .L9
.L8:
        mov     eax, DWORD PTR [rbp-12]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    printf
        mov     edi, 10
        call    putchar
.L7:
        add     DWORD PTR [rbp-4], 1
        jmp     .L10
.L2:
        mov     eax, 0
        leave
        ret

Hope it helped!!!

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