簡體   English   中英

匯編,將ascii值存儲到寄存器中

[英]assembly, storing ascii values into a register

如何將8個ascii值存儲到寄存器或變量中? 例如我在ASCII中有這些值30 30 34 20 33 32 32 00

那將是004322

80x86架構

mov eax 30303420
mov ebx 33323200

或者您可以在數據段中

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

您也可以使用堆棧(LIFO):

mov eax 30303420
mov ebx 33323200
push ebx
push eax

或到一個寄存器8字節= 8 * 8位= 64位:

mov rax 3030342033323200h

編輯:

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

為什么不使用堆棧? 特別是如果值不是常數

編輯: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