ASMx86:如何在字符串中挑选一个字母? [英] ASMx86: How to pick out a letter in a string?

查看:18
本文介绍了ASMx86:如何在字符串中挑选一个字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对字符在汇编中的工作方式感到困惑.既然一切都以位为单位,那么这是否意味着所有字符在寄存器中基本上都只是十六进制版本/ascii 值?

i'm confused on how characters work in assembly. Since everything is in bits then does that mean that all characters are basically just hexadecimal versions/ascii values when in registers?

例如,如果我想将我喜欢馅饼"放在寄存器中,它会显示为48h 4C484B45h 504945h"吗?如果我想获得所有i"字母,我需要使用像

For example if I wanted to put "I like pie" in a register will it show up as "48h 4C484B45h 504945h"? And if I wanted to get all "i" letters will I need to use a command like

;   "command to get string input"  
getI:
    cmp BYTE PTR [edx],48h 
    je L1
L1: 
    add [edx],1
    loop getI  

我基本上是想找到一种方法来从输入的字符串中分离出一个字符.

I'm basically trying to find a way to isolate a character from an inputted string.

推荐答案

您的方法已接近可行:

getI:
    cmp BYTE PTR [edx],'i'  ; your assembler will know what that is
    jne L1                  ; skip the code for 'i' handling, if it's NOT an 'i'
    ; here you do what
    ; ever you want to 
    ; with your 'i's here
L1: 
    add edx,1               ; better: 'inc edx'
    loop getI               ; loop only works, if you have CX loaded with the length of your "string"
                            ; either use it, or check for 0 chars INSIDE the loop

你的 CPU 不关心你的字符串",它只是内存中的字节数.
你的我喜欢馅饼"是字节69h,20h,6ch,69h,6bh,65h,20h,70h,69h,65h,0"的ascii表示当您将其中一个加载到寄存器中时,它只是一个字节值……字符串或字符没有什么特别之处

your CPU doesnt care for your "String", it's just an amount of bytes in memory.
Your "i like pie" is the ascii representation of the bytes "69h,20h,6ch,69h,6bh,65h,20h,70h,69h,65h,0" when you load one of these into a register, it's just a byte value ... there's nothing special about strings, or chars

顺便说一句:并非所有寄存器都是相同的,有些寄存器具有特殊用途.您已选择 edx 作为您的字符串指针"…… x86 CPU 具有带有专用指令的索引寄存器来使用它们,这会更好地为您服务.但那是另一回事了 ;-)

btw: not all register are equal, there are some that have special purposes. You've chosen edx as your "string pointer" ... x86 CPUs have index registers with specialized instructions to use them, which would've served you better. But that's a different story ;-)

这篇关于ASMx86:如何在字符串中挑选一个字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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