我怎样才能遍历同时两个字符串的字符? [英] How can I loop over the characters of two strings simultaneously?

查看:474
本文介绍了我怎样才能遍历同时两个字符串的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用TASM 3.1在Windows 8 32位。我试图在同一时间读取两个不同的字符串两个字符。即像

I'm using TASM 3.1 on windows 8 32 bit. I'm trying to read two characters from two different strings at a time. i.e. something like

for(I = 0, J = 0; I < N1 && J < N2; I++, J++)
{
    char c1 = string1[I];
    char c2 = stirng2[J];
}

我可以通过一个字符串的字符循环做

I can loop through the characters of one string by doing

mov si, offset string
start:
  mov al, [si]
  cmp al, 0
  je end
  ;do stuff with character in al
  inc si
  jmp start
end:

和我通过

.data
  string db 'abracadabra'

我怎样才能在那里得到第二个串并遍历它就像我的第一做什么?这似乎是 SI 是索引的唯一排序,我可以使用,这是不够的两个字符串。

How can I get a second string in there and iterate over it much like I'm doing with the first? It seems like si is the only sort of indexer I can use and that's not enough for two strings.

我试图做这样的事情比较两个字符串并打印具有相同的索引和值相同的字符。或在彼此的顶部添加两个人物做加法大量重新psented为字符串$ P $的。我怎样才能解决这些类型的问题,我需要在同一时间来遍历两个字符串?

I'm trying to do things like compare two strings and print only characters which have same index and same value. Or do addition of large numbers represented as strings by adding the two characters on top of each other. How can I solve these sort of problems where I need to iterate over both strings at the same time?

推荐答案

请注意您的ASM做了什么是指针迭代,而不是索引。不知道为什么你需要2个变量 I Ĵ在C code。你可以只使用1。

Note what you did in asm is pointer iteration, not indexing. Not sure why you need 2 variables I and J in the C code. You can just use 1.

    xor si, si
loop:
    mov al, [string1+si]
    mov dl, [string2+si]
    ; do something 
    inc si
    cmp si, [N1]
    jae done
    cmp si, [N2]
    jb loop

PS:在16位x86汇编,你也可以使用 BX BP 索引。
你也可以precalculate 分(N1,N2)课程。

这篇关于我怎样才能遍历同时两个字符串的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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