MASM海峡和SUBSTR? [英] MASM str and substr?

查看:216
本文介绍了MASM海峡和SUBSTR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前编码ASM一个IRC bot
我已经在C ++中做过一次,所以我知道如何解决我遇到的大部分问题,但​​我需要一个SUBSTR()[*]功能像在C ++中见过。我需要SUBSTR函数从一个PING请求,接收服务器名称,这样我就可以用相应的响应PONG回应

I'm currently coding an irc bot in asm I have already done this once in C++, so I know how to solve most problems I encounter, but I need a substr()[*] function like the one seen in C++. I need the substr function to receive the server name from a PING request so I can respond with the corresponding PONG response

但我不知道该怎么implent它在MASM,我听到了一种叫macroassembling,似乎SUBSTR往往是在这些功能中使用

But I don't know how to implent it in MASM, I heard of something called macroassembling, It seems substr is often used in those functions

没有人有任何想法,我怎样才能让我的SUBSTR功能正常工作

Does anyone have any idea how I can get my substr function to work

[*] 字符串SUBSTR(为size_t POS = 0,为size_t N =非营利机构)

这是我如何使用SUBSTR()funcion在C ++:

This is how I use the substr() funcion in C++:

if(data.find("PING :") != std::string::npos){
string pong = "PONG :" + data.substr(  (data.find_last_of(":")+1), (data.find_last_of("\r")-1)  );
SCHiMBot.Pong(pong);   // Keep the connection alive!
}

如果数据是一个字符串保存所有服务器发送我的信息,SCHiMBot是一类我使用与服务器交谈
这code是C&放大器;直接p'ed了机器人I $ C $的CD,所以它应该是完美无瑕的。

Where data is a string holding all the information the server sends me, and SCHiMBot is a class I use to talk with the server This code is c&p'ed directly out of a bot I coded, so it should be flawless

推荐答案

这真的是几乎没有容易回答的问题是它可能最初看起来。问题是pretty简单:像​​函数 SUBSTR 实际上并不存在孤立 - 这是一个字符串库的一部分,并使其有用的,你只要大约至少需要勾画出库作为一个整体是如何结合在一起,你再怎么present数据等即 SUBSTR 创建一个字符串,但要这样做,你需要决定什么字符串的

This really isn't nearly as easy to answer is it might initially seem. The problem is pretty simple: a function like substr doesn't really exist in isolation -- it's part of a string library, and to make it useful, you just about need to at least sketch out how the library as a whole fits together, how you represent your data, etc. I.e., substr creates a string, but to do so you need to decide what a string is.

要避免这样的问题,我要那种不理你居然问,并给出一个更简单的答案那是更适合汇编语言。你真正需要的是一个数据缓冲区开始,找了几个在该缓冲区标志,并复制这些标记到另一个缓冲区中的指定位置之间有什么在不在。首先,我们需要code做了find_last

To avoid that problem, I'm going to sort of ignore what you actually asked, and give a somewhat simpler answer that's more suited to assembly language. What you really need is to start with one buffer of data, find a couple of "markers" in that buffer, and copy what's in between those markers to a designated position in another buffer. First we need the code to do the "find_last":

; expects: 
; ESI = address of buffer
; ECX = length of data in buffer
; AH =  character to find
; returns:
; ESI = position of item
;
find_last proc 
    mov al, [esi+ecx]
    cmp ah, al
    loopnz  find_last
    ret
find_last endp

现在的子字符串复制到发送缓冲区,我们做这样的事情:

Now to copy the substring to the transmission buffer, we do something like this:

CR = 13

copy_substr proc
    mov esi, offset read_buffer
    mov ecx, bytes_read
    mov ah, CR
    call find_last   ; find the carriage-return
    mov edx, esi     ; save its position

    mov esi, offset read_buffer
    mov ecx, bytes_read
    mov ah, ':'
    call find_last   ; find the colon
    inc esi          ; point to character following colon
    sub edx, esi     ; get distance from colon+1 to CR
    mov ecx, edx   

    ; Now: ESI = address following ':'
    ;      ECX = distance to CR

    mov edi, (offset trans_buffer) + prefix_length
    rep movsb         ; copy the data
    ret
copy_substr endp

这篇关于MASM海峡和SUBSTR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆