简体   繁体   English

如何比较 x86 程序集中的字符

[英]How to compare characters in x86 assembly

I have the two words stored in variables just called first and second.我将这两个词存储在刚刚称为 first 和 second 的变量中。 How do I compare the characters of each string to see which one is larger?如何比较每个字符串的字符以查看哪个更大?

section .data

greet: db "Type a word: "
greetL: equ $-greet

section .bss

first: resb 20
second: resb 20

section .text

global _start

_start:
    nop
    mov eax, 4
    mov ebx, 1
    mov ecx, greet
    mov edx, greetL
    int 80H

    mov eax, 3
    mov ebx, 0
    mov ecx, first
    mov edx, 20
    int 80H

then I just do the same thing to get the second word然后我只是做同样的事情来得到第二个词

I dunno, cmp I suppose...我不知道, cmp我想...

 xor ecx, ecx ; index top mov al, [first + ecx] cmp [second + ecx], al jb first_is_bigger ja second_is_bigger cmp al, LF ; LF equ 10 je they_are_equal inc ecx jmp top

That's untested.这是未经测试的。 I've been having a lot of brain flatulence lately - better check me.我最近一直有很多脑胀气 - 最好检查一下。 If the pesky user enters more than 20 characters, you may be in deep muddy water...如果讨厌的用户输入超过20个字符,您可能会陷入泥泞的水中......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM