首页 > 解决方案 > MASM 取消引用指针两次?

问题描述

直截了当,我被困在我的一段代码中。在 checkdigit proc 中,我试图将相应内存位置的值移动到寄存器中,并使用 [] 取消引用指针。然而,通过这个我假设你不能取消引用一个指针两次,因为我已经将这些“变量”的地址推到堆栈上使用,我猜想创建另一个指针。当前代码会将我想要传递给寄存器的值的内存位置传递给寄存器,但是我无法取消引用内存位置来获取我的值。任何帮助将不胜感激,即使这意味着我将无法使用当前代码。谢谢你。

;valid pin program


 include c:/Irvine/Irvine32.inc

 NULL        EQU  0
CR      EQU 0dh
LF      EQU  0ah
 nextdigit EQU  4

 range     EQU  8[ebp]
 digit     EQU  12[ebp]

.data

 outfile byte   "resultpin.txt", NULL
 infile  byte   "Pin.txt", NULL
 input   dword  ?
 output  dword  ?

 buffer_size = 130

 buffer    byte  buffer_size dup (?), NULL
 bytesread dword ?
 buffpos   dword 0
 pinpos    dword 1

 digitnum  dword 0

 range1    dword     '4', '8', NULL
 range2    dword     '2', '5', NULL
 range3    dword     '5', '9', NULL
 range4    dword     '1', '4', NULL
 range5    dword     '3', '6', NULL

 rangeray  dword     range1, range2, range3, range4, range5, NULL
 rangepos  dword     12                            
;memory offset is 60

 equal     byte      "=", NULL

 great     byte      "PIN is valid", NULL

 fault1    byte     "/Digit position ", NULL
 fault2    byte      "is invalid/", NULL

 faultray  dword     fault1, fault2, NULL          
;memory offset is 29
 faultpos  dword     17

 gap       byte      LF, CR, NULL


.code
main proc

      lea edx, outfile              ;create & open output file
    call CreateOutputFile
    mov output, eax

      lea  esi,infile               ;open input file linkage
      call openfiles

      lea  esi,buffer
      mov  ecx,digitnum
      call countdigits

      call resetregs

      lea  esi,buffer
      lea  edi,rangeray
      add  edi,-60                  ;start at beginning of rangeray
      mov  ecx,digitnum
 L1:
      push esi
      push edi
      push ebp

      call checkdigit
      pop  ebp
      pop  edi
      pop  esi
      loop L1
 main endp

 openfiles proc
      lea edx,[esi]                 ;open file      
    call OpenInputFile
    mov input, eax 

    mov  eax, input               ;read input 
   file
    lea  edx, buffer
    mov  ecx, buffer_size
    call ReadFromFile
    mov  bytesRead, eax
      ret
 openfiles endp

 countdigits proc
   nextnumber:
      mov  dl,[esi]                 ;if not a 
  number bypass inc ecx
      cmp  dl,'0'
      jl   notdigit
      cmp  dl,'9'
      jg   notdigit

      inc ecx

   notdigit:
      inc  esi
      mov  dl,[esi]
      cmp  dl,NULL                  ;if esi 
is NULL then return out of proc
      jne  nextnumber

      mov  digitnum,ecx
      ret
 countdigits endp

 checkdigit proc
      mov  ebp,esp
      mov  ebx,digit
      mov  edx,range
      cmp  ebx,edx
      jl   notvalid
      mov  ebx,0
   notvalid:
      ret
 checkdigit endp

 resetregs proc
      mov  eax,0                    ;reset 
  following registers
      mov  ebx,0
      mov  ecx,0
      mov  edx,0
      mov  dl,0
      mov  al,0
      ret
 resetregs endp


end main

标签: pointersmasm

解决方案


推荐阅读