I need help with my assi. I don't even understand what the questionis . Q. write a program that will input an integer valve and calculate the value of nBr where nBr is the smallest integer such that 1^2 + 2^2 + 3^2 +....... nBr^2 >= value
( these are square of one and two .....)
for example if you input 50, then the program would display 5 since 1+4+9+16 = 30, but 1+4+9+16+25= 55

2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by ipride

So can you do the very first step, and the very last step?

- and display it
?

These things are built one step at a time. Don't look at the whole assignment, imagine smaller parts.

So can you do the very first step, and the very last step?

- and display it
?

These things are built one step at a time. Don't look at the whole assignment, imagine smaller parts.

well here is the design that I came up with

Value: = 0;
number := 0;
While(value <= number)
Multiply number x number
Until (value == number);

does it look ok?

> Multiply number x number
And do what with it?

> While(value <= number)
> Until (value == number);
Huh?

You need
- a loop variable counting 1 2 3 ....
- a sum for 1^2 + 2^2 etc
- a target value (read from the user)

> Multiply number x number
And do what with it?

> While(value <= number)
> Until (value == number);
Huh?

You need
- a loop variable counting 1 2 3 ....
- a sum for 1^2 + 2^2 etc
- a target value (read from the user)

ok here what I've done sofar but I'm still running into errors

``````.586
.MODEL FLAT

INCLUDE io.h            ; header file for input/output

.STACK 4096

.DATA
targetValue   DWORD   ?
nbrTerms      DWORD   ?
number        DWORD   ?
prompt1 BYTE    "Enter the integer value", 0
string  BYTE    40 DUP (?)
resultLbl BYTE  "Number of terms", 0
nbrTerms     BYTE    11 DUP (?), 0

.CODE
_MainProc PROC
input   prompt1, string, 40      ; read ASCII characters
atod    string                        ; convert to integer
dtoa    targetValue, ecx         ; convert to ASCII characters
mov     ecx,targetValue	   ;store targetValue in ecx
mov     eax,nbrTerms	   ;store nbrTerms in eax
mov	ah,number	  ;store number in ah

whileB:     cmp     nbrTerms,1	  ;nbrTerms==1
jne     endwhileB		  ;exit if not equal

mul	ah,ah		  ;multiply number by itself
ifB:	cmp	ecx,eax	  ;comparing targetVale to nbrTerms
jnle   ifB	                 ;exit if not targetVale<= nbrTerms