0

私は現在NASMを使い始めており、NASMでレジスタの内容を16進数で出力する方法を知りたいと思っていました。eaxの内容を出力できます

section .bss
    reg_buf: resb 4
.
.
.
print_register:
    mov [reg_buf], eax
    mov eax, SYS_WRITE
    mov ebx, SYS_OUT
    mov ecx, reg_buf
    mov edx, 4
    int 80h
    ret

eax に 0x44444444 が含まれているとします。出力は「DDDD」になります。どうやら「44」の各ペアは「D」として解釈されます。私の ASCII テーブルはこれを承認します。

しかし、実際のレジスタの内容 (0x44444444) をプログラムに出力させるにはどうすればよいでしょうか?

4

2 に答える 2

1

教えてもらったのはこんな感じ。。

.
.
SECTION .data
numbers: db "0123456789ABCDEF" ;; have initialized string of all the digits in base 16
.
.
.
  ;;binary to hex

mov al , byte [someBuffer+someOffset] ;; some buffer( or whatever ) with your data in
mov ebx, eax  ;; dealing with nybbles so make copy for obtaining second nybble

and al,0Fh   ;; mask out bits for first nybble
mov al, byte [numbers+eax] ;; offset into numbers is the hex equiv in numbers string
mov byte [someAddress+someOffset+2], al
;;store al into a buffer or string or whatever it's the first hex number

shr bl, 4 ;; get next nybble
mov bl, byte [numbers+ebx] ;; get the hex equiv from numbers string
mov byte [someAddress+someOffset+1], bl
;;place into position next to where al was stored, this completes the process,
;;you now have your hexadecimal equivalent output it or whatever you need with it
.
.
.
于 2013-02-17T23:54:42.520 に答える
0

最初にレジスタをテキスト文字列としてフォーマットする必要があります。最も簡単に使用できる API は、おそらく でありitoa、その後に書き込み呼び出しが続きます。これを機能させるには、文字列バッファを割り当てる必要があります。

アセンブリでそれを行いたくない場合は、プログラムから読み取り、すべての出力テキストを作成する簡単な C/Python/Perl/etc プログラムを作成できます。

于 2010-06-07T18:22:00.557 に答える