大会32位 - 如何检查字符串 [英] Assembly 32bit - how to check a string

查看:157
本文介绍了大会32位 - 如何检查字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有收到一个字符串,并将其传递给字符串是否仅由字母数字字符,它检查汇编函数,如果这个函数查找非字母数字烧焦它删除它的C程序。一旦完成了字符串,该函数返回的字符串检查

I have a C program that receive a string and pass it to an Assembly function which checks if the string is made only of alphanumeric characters, if this function finds a non alphanumeric char it has to delete it. once finished the string, the function returns the checked string.

我不知道该如何沿着字符该字符串字符运行检查它们是否有效。

I don't know how to run along that string char by char to check if they are valid.

我怎样才能做到这一点?

How can I do this?

推荐答案

这是你怎么做。下一步code与Visual Studio 2010的C ++控制台项目的。首先,组装部分,要注意的意见,如何从堆栈中,人物是如何获得访问字符串的地址,而最重要的组成部分,如何不想要的字符被删除:

This is how you do it. Next code was made with Visual Studio 2010 C++ console project. First, the assembly part, pay attention to the comments, how to get the string's address from stack, how the characters are visited, and the most important part, how the undesired chars are deleted:

.386
.model flat, C
.code
;-------------------------------------------------------
check_alphanum proc

;PRESERVE EBP, ESI.
  push ebp
  push esi

  mov  ebp, esp
  add  ebp, 12          ;GET PARAMETER'S ADDRESS.
  mov  esi, [ ebp ]     ;ESI POINTS TO ARRAY.
whil:
  mov  al, [ esi ]      ;GET CURRENT CHAR.
  cmp  al, 0            ;CHECK END OF ARRAY.
  je   finale           ;IF ( AL == 0 ) END OF STRING.

;CHECK IF CURRENT CHAR IS 0..9-A..Z-a..z.
  cmp  al, '0'
  jb   its_invalid      ;IF ( AL <  '0' ) INVALID.
  cmp  al, '9'
  jbe  its_valid        ;IF ( AL <= '9' ) VALID.
  cmp  al, 'A'
  jb   its_invalid      ;IF ( AL <  'A' ) INVALID.
  cmp  al, 'Z'
  jbe  its_valid        ;IF ( AL <= 'Z' ) VALID.
  cmp  al, 'a'
  jb   its_invalid      ;IF ( AL <  'a' ) INVALID.
  cmp  al, 'z'
  jbe  its_valid        ;IF ( AL <= 'z' ) VALID.
  jmp  its_invalid      ;INVALID BECAUSE AL > 'z'.

its_valid:
;NEXT CHAR TO PROCESS.
  inc  esi
  jmp  whil

its_invalid:
;DELETE CURRENT CHAR PUSHING ALL CHARS ONE PLACE TO THE LEFT.
  mov  edi, esi         ;EDI POINTS TO CURRENT CHAR TO DELETE.
  mov  ebx, esi         ;EBX ALSO POINTS TO CURRENT CHAR.
  inc  ebx              ;NOW EBX POINTS TO NEXT CHAR.
shifting_left:
  mov  al, [ ebx ]      ;AL = NEXT CHAR.
  mov  [ edi ], al      ;CURRENT CHAR REPLACED BY NEXT.
  cmp  al, 0
  je   end_shifting
  inc  edi
  inc  ebx
  jmp  shifting_left
end_shifting:

  jmp  whil             ;REPEAT PROCESS FOR NEXT CHAR.

finale:

;RESTORE EBP, ESI.
  pop  esi
  pop  ebp

  ret
check_alphanum endp
;-------------------------------------------------------
end

现在C ++的一部分。 previous过程可以称为像这样,例如,从主的方法:

Now the C++ part. Previous procedure can be called like this, for example, from the "main" method:

extern "C" void check_alphanum ( char * arr );
...
char arr[] = "A213457B-3746DFA3-578EC20E-4567DFF2-08A1B3AC-7B125F3A";
check_alphanum( arr );

结果字符串是:

"A213457B3746DFA3578EC20E4567DFF208A1B3AC7B125F3A"

下一图片显示了在项目树的外部组件文件:

Next image shows where is the external assembly file in the project tree:

所有你所要做的就是添加一个新的文件到您的项目,只要你想的名字,但使用.ASM扩展名,复制粘贴我的code在里面,这就是它,准备使用(或准备调用)。

All you have to do is add a new file to your project, name it as you want but use the ".asm" extension, copy-paste my code in it, and that's it, ready to use (or ready to call).

这篇关于大会32位 - 如何检查字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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