【问题标题】:Invalid instruction operands error during if statement in MASM [duplicate]MASM 中的 if 语句期间出现无效指令操作数错误 [重复]
【发布时间】:2013-04-12 20:30:53
【问题描述】:

我对 MASM 非常陌生,并且在使用 if 语句时遇到了问题。我得到的编译错误是:RNG.asm(61) : error A2070: invalid instruction operands。 (第 61 行从下往上 5 个)

这是我的代码:

;=====================================================================
; RNG.asm
;
; Reads in: a low int, a high int, and the number of times to generate
; a random number inbetween the low and high value.
;
;Author: Ian Johnson
;Date Created: 4/12/13
;=====================================================================
.386
.model flat,stdcall
.stack

include \masm32\include\irvine32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\irvine32.lib
includelib \masm32\lib\kernel32.lib

.data
  min   BYTE "Please enter the min value:"           , 10,0
  max   BYTE "Please enter the max value:"           , 10,0
  times BYTE "please enter the number of iterations:", 10,0

  minInt   DWORD ?          ;minimum value
  maxInt   DWORD ?          ;max value
  timesInt DWORD ?          ;number of iterations
  prevInt  DWORD ?          ;previous random number or initial value
  count    DWORD ?


.code
  main proc   ;start of main procedure
    mov EDX, offset min     ;move min to EDX
    call WriteString        ;print min string
    call ReadInt            ;readin int to EAX
    mov minInt, EAX         ;store EAX value in minInt

    mov EDX, offset max     ;move max to EDX
    call WriteString        ;print max string
    call ReadInt            ;readin int to EAX
    mov maxInt, EAX         ;store EAX value in maxInt

    mov EDX, offset times   ;move times to EDX
    call WriteString        ;print times string
    call ReadInt            ;readin int to EAX
    mov timesInt, EAX       ;store EAX value in timesInt 

    call GetMseconds        ;stores Mseconds in EAX
    mov prevInt, EAX        ;store getMseconds in prevInt
    mov count,0
L1:    
    mov EAX, minInt         ;move minInt to EAX
    mov ECX, prevInt        ;move prevInt to ECX
    mul ECX                 ;EAX = minInt * prevInt
    mov EBX, maxInt         ;move maxInt to EBX
    div EBX                 ;EAX = (min*prev) / max
    mov prevInt, EDX        ;EDX holds remainder from divison
    mov EAX, EDX            ;move random number to EAX
    call WriteInt           ;write random number
    INC count               ;increment count
    .IF count < timesInt    ;if count < timesInt continue
         LOOP L1            ;jump to L1
    .ENDIF                  ;end IF

    invoke ExitProcess,0    ;exit process
  main endp
  end main

感谢您的宝贵时间,

伊恩

【问题讨论】:

    标签: if-statement assembly x86 masm irvine32


    【解决方案1】:

    根据Operators Reference的关系运算符是

    均衡器
    GE 表示大于或等于
    GT 大于
    LE 表示小于或等于
    LT 小于
    NE表示不等

    我建议将 &lt; 更改为 LT,这应该可以解决您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多