In: Computer Science
##Notice: write in HLA code
.
.
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( "\n" );
}
else { // internal rows of the box
printf( "%d", n );
for (j = 1; j <= n-2; j++) {
printf( " " );
}
printf( "%d", n );
printf( "\n" );
}
}
.
##Answer the questinon in HLA Assembly language program.
The code is as follows:
.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 eax, DWORD PTR [rbp-12]
test eax, eax
js .L15
mov DWORD PTR [rbp-4], 1
jmp .L4
.L12:
cmp DWORD PTR [rbp-4], 1
je .L5
mov eax, DWORD PTR [rbp-12]
cmp DWORD PTR [rbp-4], eax
jne .L6
.L5:
mov DWORD PTR [rbp-8], 1
jmp .L7
.L8:
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
.L7:
mov eax, DWORD PTR [rbp-12]
cmp DWORD PTR [rbp-8], eax
jle .L8
mov edi, 10
call putchar
jmp .L9
.L6:
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
jmp .L10
.L11:
mov edi, 32
call putchar
add DWORD PTR [rbp-8], 1
.L10:
mov eax, DWORD PTR [rbp-12]
sub eax, 1
cmp DWORD PTR [rbp-8], eax
jl .L11
mov eax, DWORD PTR [rbp-12]
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov edi, 10
call putchar
.L9:
add DWORD PTR [rbp-4], 1
.L4:
mov eax, DWORD PTR [rbp-12]
cmp DWORD PTR [rbp-4], eax
jle .L12
mov eax, 0
jmp .L1
.L15:
nop
nop
.L1:
leave
ret