将字符串 IP 地址转换为 32 位整数 (ASM)

问题描述

我想弄清楚如何将空终止的普通 IP 地址作为字符串并将其转换为 32 位整数。在此示例中,我的字符串位于地址 ES:DI+Qapktdat。 Qapktdat 是定义为存储在 ES:DI 中的字符串的结构体的成员。

我在结构体中读取或写入字符串没有问题,但计算 IP 时遇到问题。

例如,如果我使用字符串“192.168.7.2”,那么 EDX 应该等于十六进制值 C0A80702,但我没有得到任何接近它。

我可能做错了什么?

ipconvmath:
  mov BX,Qapktdat-1 ;BX=data pointer. Set it to beginning of data -1
  mov CX,11h ;Look for null within the first 17 bytes of data
  ipend:
    inc BX
    mov AL,[ES:DI+BX]
    cmp AL,0
    je ipok
  loop ipend
  mov DX,-1 ;cant find null char so exit
  ret
  ipok:
  mov BP,10   ;BP = multiplier of multiplier
  xor EDX,EDX ;EDX = eventual IP address
  ;We scan IP address starting at LAST digit
  nextipseg:
    mov CX,1  ;CX= immediate multiplier
    xor DL,DL ;lower 8 bits of EDX = 0
    nxb:
      xor AX,AX
      dec BX
      mov AL,[ES:DI+BX]
      cmp AL,'.'
      je nodot
    ;Input isnt DOT so see if its number 0-9
    cmp AL,30h ;#0
    jb badipcnv
    cmp AL,39h ;#9
    ja badipcnv
    sub AL,30h
    mul CX ;multiply by 1,10,or 100 depending on number position
    add DL,AL ;add it to our numeric IP
    mov AX,CX ;temporarily make AX=CX so multiply can work
    mul BP ;multiply the immediate multiplier by 10
    mov CX,AX
    cmp BX,Qapktdat ;see if were at beginning of data
    jne nxb
    ;we are so skip beginning
    nodot:
    rol EDX,8 ;shift existing contents over by 1 byte
  cmp BX,Qapktdat ;see if were at beginning 
  jne nextipseg
  ;here we are at beginning so were done
  ;EDX = ip address converted
  ret

  ;Reach here if a character is not 0-9 or a dot
  badipcnv:
    mov AX,1
  ret

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)