News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Eror 2071 and 2070 - new to MASM

Started by gweglarz, March 17, 2015, 12:12:51 AM

Previous topic - Next topic

gweglarz


I am getting error 2071 and 2070 on line 37. I'm taking a class and we are using the Kip Irviine book.
http://kysmykseka.net/koti/wizardry/Programming/Assembly/Assembly%20Language%20for%20x86%20Processors%206th%20Ed.pdf
problem 5.8 #5

TITLE Program Template     (BetterRandomGenerator.asm)

; Better Random Number Generator

Include Irvine32.inc
.data

str1 BYTE "Please enter a positive integer for the starting number for Random Gnerator: ", 0   ; Prompt for begining integer
str2 BYTE "Please enter a positive integer for the ending number for Random Gnerator: ", 0      ; Prompt for ending integer
str3 BYTE "Random Integers: " ,0                                                ; Message string whgen displaying return integers
str4 BYTE "Interger must be greater than 0 ", 0                                       ; message for entering positive integer
str5 BYTE "End must be greater than start ", 0                                       ; message for end value must be greater than start value
comma BYTE ", "                                                               ; comma   
startInputValue SDWORD ?                                                      ; Var for begining interger value
endInputValue   SDWORD ?                                                      ; Var for ending interger value

.code
main PROC

L1:   mov edx, OFFSET str1                                                      ; after execution edx should contain str1
   call WriteString                                                         ; WriteString should write str1 to console
   call Readint                                                            ; should read integer from console and place integer value in eax
.IF startInputValue < 0                                                      ; check to see iff startInputValue is positive
   push edx                                                               ; push edx stack
   mov edx, OFFSET str4                                                      ; after execution edx should contain str4
   call WriteString                                                         ; Write MEssage to console
   pop edx                                                                  ; pop edx stack
   loop L1                                                                  ; condition wasn't met;return to loop L1               
.ELSE                                                                     ; condition met, continue
   mov startInputValue, eax                                                   ; after execution mInputValue should contain starting integer
.ENDIF
L2:
   mov edx, OFFSET str2                                                      ; after excution edx should contain str1
   call WriteString                                                         ; WriteString should write str2 to console
   call Readint                                                            ; should read integer from console and place integer value in eax
   mov endInputValue, eax                                                      ; after execution, endInputValue should contsin eax
.IF (endInputValue <= startInputValue) || (endInputValue == 0)                           ; Check to see if ending value is <= to starting value or ==to 0
   push edx                                                               ; push edx
   mov edx, OFFSET str5                                                      ; after execution edx should contain str5
   call WriteString                                                         ; Write edx to console
   pop edx                                                                  ; pop edx
   loop L2                                                                  ; return to L2 to repeat input
.ENDIF

   call BetterRandomGenerator                                                   ; Call procedure
   exit
main ENDP


BetterRandomGenerator PROC USES eax ebx
   call Randomize                                                            ; seed RandomRange
   mov ecx, 50                                                               ; initialize counter to 50
L2: mov eax, endInputValue                                                      ; after execution eax should contain endInputValue
   call RandomRange                                                         ; call RandomRange that has a starting value of 0
.IF eax < startInputValue                                                      ; check to see if returned value in eax from RandomRange < startInputValue
   loop L2                                                                  ; if eax < nstartInputValue return to loop
.ELSE
   call WriteInt                                                            ; Write integer to consoloe
   mov edx, OFFSET comma                                                      ; write comma
.ENDIF
   loop L2                                                                  ; continue loop
   call WaitMsg                                                            ; Write "Press any key to continue..." to console
ret
BetterRandomGenerator ENDP


END main

dedndave

that's a pretty easy one   :biggrin:

   mov endInputValue, eax
.IF (endInputValue <= startInputValue) || (endInputValue == 0)


there are only a few ways to perform memory-to-memory operations - this isn't one of them
most operations (mov, add, cmp) must be done register-to-register, register-to-memory, register-to-immediate, or memory-to-immediate

as it happens, you have "endInputValue" in EAX, so.....

   mov endInputValue, eax
.IF (eax <= startInputValue) || (eax == 0)


the compare with 0 doesn't have to be done register-to-immediate,
it's just smaller and faster because you already have the value in register
(probably not needed as, if EAX is 0, it will also be less than startInputValue)

gweglarz

Thanks. After I posted, I figured it out.

dedndave

 :t

by the way - what i meant by "pretty easy" was...
compared to another problem i was working on - lol