Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROGRAM 5 : Real Big Number! Write an HLA Assembly language program that prompts for n , an int 8 value, and then displays a

PROGRAM 5: Real Big Number!
Write an HLA Assembly language program that prompts for n, an int8 value, and then displays a repeated digit pattern starting with that number. The repeated digit pattern should print all the values from 1 up to n then all the values from 1 up to n-1 then all the values 1 up to n-2... then all the values 1 up to 2 and end with a single 1. Shown below is a sample program dialogue.
Gimme a decimal value to use for n: 5
Here's your answer: 123451234123121
Gimme a decimal value to use for n: 8
Here's your answer: 123456781234567123456123451234123121
(Hint: The digit pattern is too large to store into any datatype we have learned to date so I am expecting that you will use a loop with CMP instructions and a conditional jump to print individual digits, rather than store the complete number in a variable, just like the sample programs in this unit demonstrate)
(Additional Hint: You should not be using high language statements like for, while or repeat loops, as these are not assembly instructions are off limits in this course.)
Withoug using high level programming such as loops and if statements.
Here is my c code that works but want to convert to HLA assembly
#include
void printDigitPattern(int n){
int i, j;
for (i =1; i <= n; ++i){
for (j =1; j <= i; ++j){
printf("%d", j);
}
}
for (i = n -1; i >=1; --i){
for (j =1; j <= i; ++j){
printf("%d", j);
}
}
printf("1
"); // End with a single '1' and newline
}
int main(){
int n;
printf("Gimme a decimal value to use for n: ");
scanf("%d", &n);
printf("Here's your answer: ");
printDigitPattern(n);
return 0;
}
Heres the code i have but error at line 20
program RealBigNumber;
#include("stdlib.hhf")
static
n: int8;
i: int8;
j: int8;
begin RealBigNumber;
// Prompt user for input
stdout.put("Gimme a decimal value to use for n: ");
stdin.get(n);
// Print the pattern
stdout.put("Here's your answer: ");
// First half: from 1 up to n
mov(1, i);
FirstLoop:
cmp(i, n);
jg(EndFirstLoop);
mov(1, j);
InnerFirstLoop:
cmp(j, i);
jg(EndInnerFirstLoop);
stdout.put(j,"");
inc(j);
jmp InnerFirstLoop;
EndInnerFirstLoop:
inc(i);
jmp FirstLoop;
EndFirstLoop:
// Second half: from n-1 down to 1
dec(n);
SecondLoop:
cmp(n,1);
jl(EndSecondLoop);
mov(1, j);
InnerSecondLoop:
cmp(j, n);
jg(EndInnerSecondLoop2);
stdout.put(j,"");
inc(j);
jmp InnerSecondLoop;
EndInnerSecondLoop2:
dec(n);
jmp SecondLoop;
EndSecondLoop:
// End with a single '1'
stdout.put("1
");
end main;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

2 What is the philosophy of performance management?

Answered: 1 week ago