简体   繁体   English

汇编,将ascii值存储到寄存器中

[英]assembly, storing ascii values into a register

How would I store 8 ascii values into a register or a variable? 如何将8个ascii值存储到寄存器或变量中? For instance I have these values in ascii 30 30 34 20 33 32 32 00 例如我在ASCII中有这些值30 30 34 20 33 32 32 00

Which would be 004 322 那将是004322

80x86 architecture 80x86架构

mov eax 30303420
mov ebx 33323200

or you can do in the data segment 或者您可以在数据段中

var db 30 , 30 ,34 ,20 ,33 ,32 ,32, 00

you can use the stack(LIFO) as well: 您也可以使用堆栈(LIFO):

mov eax 30303420
mov ebx 33323200
push ebx
push eax

or to one register 8 byte = 8*8 bit = 64 bit: 或到一个寄存器8字节= 8 * 8位= 64位:

mov rax 3030342033323200h

EDIT: 编辑:

extern  printf      ; the C function, to be called

SECTION .data       ; Data section, initialized variables

a:  db  30 , 30 ,34 ,20 ,33 ,32 ,32, 00 
fmt:    db "a=%s",'0'


SECTION .text                   ; Code section.

global main     ; the standard gcc entry point
main:               ; the program label for the entry point
push    ebp     ; set up stack frame
mov     ebp,esp

push    a           ; value of variable a
push    fmt
call    printf      ; Call C function
add     esp, 8      ; maybe I missed some bytes here 

mov     esp, ebp    ; takedown stack frame
pop     ebp     ; same as "leave" op

mov eax,0       ;  normal, no error, return value
ret         ; return

Why not use the stack? 为什么不使用堆栈? Especially if the values are not constants 特别是如果值不是常数

EDIT: woops might need some adjustment for 32-bit words :) 编辑:woops可能需要对32位单词进行一些调整:)

; load values
PUSH 30
PUSH 30
PUSH 34
PUSH 20
PUSH 33
PUSH 32
PUSH 32
PUSH 0

; do stuff
; [ESP] = 0  (last value)
; [ESP+7] = 30  (first value)

; restore stack pointer  ("free memory")
SUB ESP, 8

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

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