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: 3915627 • Letter: C

Question

Create an HLA Assembly language program that prompts for a single integer value from the user and prints an arrow 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: 3
X
XX
XXX
XX
X

Feed Me: -6

Feed Me: 5
X
XX
XXX
XXXX
XXXXX
XXXX
XXX
XX
X


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, j, n;
printf( "Feed Me:" );
scanf( "%d", &n );
// the top half of the arrow...
for( i = 1; i <= n; i++ ) {
for (j = 1; j <= i; j++) {
  printf( "X" );
}
printf( " " );
}

// the bottom half of the arrow...
for (i = n - 1; i >= 1; i--) {
for (j = 1; j <= i; j++) {
  printf( "X" );
}
printf( " " );
}

My Code is as follows:

program pattern;
#include( "stdlib.hhf" );
static

zI: int8 := 0;
zJ: int8 := 0;
zN: int8 := 0;

begin pattern; //Begin program

stdout.put( "Feed Me: ", nl ); //Ask the user for input
stdin.get( zN ); //Get value from user and store it as zN
mov( zN, AL ); //Store zN in the AL register

LpA: //Begin first outer for loop

InitLpA:
mov( 1, zI ); //Initialize loop A. Move 1 to zI (zI = 1)
mov( zI, AH ); //Move memory var zI to AH reg

LpATerminationTest:
cmp( AH, AL ); //Compare zI (AH) to zN (AL)
jge LpAExit; //Jump if zI (AH) is less than or equal (<=) to zN (AL)
jmp LpB; //Otherwise jump to the body of loop A

LpB: //Begin first inner loop

InitLpB:
mov( 1, zJ ); //Initialize loop B. Move 1 to zJ (zJ = 1)
mov( zJ, BL ); //Move memory var zJ to BL reg

LpBTerminationTest:
cmp( BL, AH ); //Compare zJ (BL) to zI (AH)
jge LpBExit; //Jump if zJ (BL) is less than or equal (<=) to zI (AH)
jmp LpBBody; //Otherwise jump to first inner loop body

LpBBody:
stdout.put( "X" ); //Print to screen char X

LpBIncrement:
inc( BL ); //Increment zJ++ (BL)

LpBExit:
jmp LpABody; //Exit inner loop by jumping to body of outer loop

LpABody:
stdout.put( nl ); //Print new line to screen

LpAIncrement:
inc( AH ); //Increment zI++ (AH)

LpAExit:
jmp LpC; //Exit first outer loop by jumping to second outer loop

LpC: //Begin second outer loop

InitLpC:
sub( 1, AL ); //Subtract 1 from zN (AL)...(zN - 1)
mov( AL, AH ); //Move the new value stored in AL register (zN) to (zI) AH register...(zI = zN)

LpCTerminationTest:
cmp( AH, 1 ); //Compare zI (AH) to 1
jle LpCExit; //Jump if zI (AH) is grater than or equal (<=) to 1
jmp LpD; //Otherwise jump to the body of second inner loop D

LpD: //Begin second inner loop

InitLpD:
mov( 1, zJ ); //Initialize loop B. Move 1 to zJ (zJ = 1)
mov( zJ, BL ); //Move memory var zJ to BL reg

LpDTerminationTest:
cmp( BL, AH ); //Compare zJ (BL) to zI (AH)
jge LpDExit; //Jump if zJ (BL) is less than or equal (<=) to zI (AH)
jmp LpDBody; //Otherwise jump to second inner loop body

LpDBody:
stdout.put( "X" ); //Print to screen char X

LpDIncrement:
inc( BL ); //Increment zJ++ (BL)

LpDExit:
jmp LpCBody; //Exit inner loop by jumping to body of outer loop

LpCBody:
stdout.put( nl ); //Print new line to screen

LpCDecrement:
Dec( AH ); //Decrement zI-- (AH)

LpCExit: //End of second outer loop

end pattern; //End program

I don't understand how its skipping over all the loops and just terminating. Please help.

Explanation / Answer

.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

.L5:

mov eax, DWORD PTR [rbp-12]

cmp DWORD PTR [rbp-4], eax

jg .L2

mov DWORD PTR [rbp-8], 1

.L4:

mov eax, DWORD PTR [rbp-8]

cmp eax, DWORD PTR [rbp-4]

jg .L3

mov edi, 88

call putchar

add DWORD PTR [rbp-8], 1

jmp .L4

.L3:

mov edi, 10

call putchar

add DWORD PTR [rbp-4], 1

jmp .L5

.L2:

mov eax, DWORD PTR [rbp-12]

sub eax, 1

mov DWORD PTR [rbp-4], eax

.L9:

cmp DWORD PTR [rbp-4], 0

jle .L6

mov DWORD PTR [rbp-8], 1

.L8:

mov eax, DWORD PTR [rbp-8]

cmp eax, DWORD PTR [rbp-4]

jg .L7

mov edi, 120

call putchar

add DWORD PTR [rbp-8], 1

jmp .L8

.L7:

mov edi, 10

call putchar

sub DWORD PTR [rbp-4], 1

jmp .L9

.L6:

mov eax, 0

leave

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