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

Create two HLA Assembly language programs: 1.Create an HLA Assembly language pro

ID: 3913766 • Letter: C

Question

Create two HLA Assembly language programs:

1.Create an HLA Assembly language program that prompts for two values from the user. Print a number pattern where both numbers are displayed a certain number of times that is controlled by the second value entered. If either number entered is zero or less, don't print anything.

Here are some example program dialogues to guide your efforts:

Provide a first number: 12
Provide an second number: 5
125_125_125_125_125

Provide a first number: 44
Provide an second number: 1
441

Provide a first number: 12
Provide an second number: -5

Provide a first number: -1
Provide an second number: 12

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

SAMPLE C CODE:
------------------------
int i, first, second;
printf( "Provide a first number: " );
scanf( &first );
printf( "Provide an second number: " );
scanf( &second);

if (first > 0) {

for (i = 1; i >= second; i++ )
{
if (i != 1)
{
printf( "_" );
}

printf( "%d", first );
printf( "%d", second );

}
printf( " " );

}

2.

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( " " );

}

Explanation / Answer

Assembly Program for first sample program:

-------------------------------------------------------------------------------------------------------------

.LC0:

.string "Provide a first number: "

.LC1:

.string "%d"

.LC2:

.string "Provide an second number: "

main:

push rbp

mov rbp, rsp

sub rsp, 16

mov edi, OFFSET FLAT:.LC0

mov eax, 0

call printf

lea rax, [rbp-8]

mov rsi, rax

mov edi, OFFSET FLAT:.LC1

mov eax, 0

call scanf

mov edi, OFFSET FLAT:.LC2

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-8]

test eax, eax

jle .L2

mov DWORD PTR [rbp-4], 1

.L5:

mov eax, DWORD PTR [rbp-12]

cmp DWORD PTR [rbp-4], eax

jg .L3

cmp DWORD PTR [rbp-4], 1

je .L4

mov edi, 95

call putchar

.L4:

mov eax, DWORD PTR [rbp-8]

mov esi, eax

mov edi, OFFSET FLAT:.LC1

mov eax, 0

call printf

mov eax, DWORD PTR [rbp-12]

mov esi, eax

mov edi, OFFSET FLAT:.LC1

mov eax, 0

call printf

add DWORD PTR [rbp-4], 1

jmp .L5

.L3:

mov edi, 10

call putchar

.L2:

mov eax, 0

leave

ret

---------------------------------------------------------------------------------------------

Assembly program for sample program 2:

---------------------------------------------------------------------------------------------

.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, 88

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

ret

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