2012-03-14 9 views
0

私のNASMプログラムの下位部分は、整数をとり、画面に印刷するためにASCIIに変換しようとしていますが、動作しません。どうしていいか分からない。半分/倍増のことを無視してください。これは、私が除外したプログラムの他の部分です。NASM整数からASCIIへの変換アルゴリズムが動作しない

segment .data         ;data segment 
    return   db  0xA      ;return character 

segment .bss         ;uninitialized data 
    numc   resb 4    ;reserve 4 bytes for the converted number (int) 
    numh   resb 5    ;reserve 5 bytes for halved input number 
    numha   resb 5    ;reserve 5 bytes for the halved number in  ascii form 
    numd   resb 5    ;reserve 5 bytes for doubled input number 
    numda   resb 5    ;reserve 5 bytes for the doubled number in ascii form 

segment .text         ;code segment 
    global _start       ;global program name 

_start: 
    mov  ebx, 1234    ;number to be converted 
    mov  [numc], ebx 

_inttoascii:       ;set registers up 
    mov  eax, [numc] 
    xor  ebx, ebx 
    xor  edx, edx 
    mov  ecx, 32 

_loop2: 
    xor  edx, edx    ;clear edx 
    mov  ebx, 10     ;divide eax by ten 
    div  ebx 
    add  edx, 48     ;add 48 to the remainder (ascii of 0 is 48) 
    mov  [numha+ecx], edx  ;move result to the correct spot in memory 
    sub  ecx, 8     ;switch to another byte for next iteration 

    cmp  eax, 0     ;if eax register is exhausted, we're done. 
    jg  _loop2 


_inttoascii2:       ;set registers up 
    mov  eax, [numc] 
    xor  ebx, ebx 
    xor  edx, edx 
    mov  ecx, 32 

_loop3: 
    xor  edx, edx    ;clear edx 
    mov  ebx, 10     ;divide eax by ten 
    div  ebx 
    add  edx, 48     ;add 48 to the remainder (ascii of 0 is 48) 
    mov  [numda+ecx], edx  ;move result to the correct spot in memory 
    sub  ecx, 8     ;switch to another byte for next iteration 

    cmp  eax, 0     ;if eax register is exhausted, we're done. 
    jg  _loop3 

    mov  eax, 4       ;select kernel call #4 (write number storing half) 
    mov  ebx, 1       ;default output device 
    mov  ecx, numha      ;pointer to numh 
    mov  edx, 5       ;length of numh 
    int  0x80       ;kernel call to write 

    mov  eax, 4       ;select kernel call #4 (new line) 
    mov  ebx, 1       ;default output device 
    mov  ecx, return      ;pointer to return character 
    mov  edx, 1       ;length of return character 
    int  0x80 

    mov  eax, 4       ;select kernel call #4 (write number storing double) 
    mov  ebx, 1       ;default output device 
    mov  ecx, numda      ;pointer to numd 
    mov  edx, 5       ;length of numd 
    int  0x80       ;kernel call to write 

    mov  eax,4       ;select kernel call #4 (new line) 
    mov  ebx,1       ;default output device 
    mov  ecx, return      ;pointer to return character 
    mov  edx, 1       ;length of return character 
    int  0x80       ;kernel call to write 

exit: mov  eax, 1       ;select system call #1 
    int  0x80       ;kernel call to exit 

出力気圧がちょうど空白行です:

は、ここに私のコードです。私はビットではなく、バイトでメモリアドレスを移動していた

+0

何とかされている必要があり、私は少しではなく、バイトでメモリアドレスを移動していた。 mov ecx、32 mov [numha + ecx]、edx;結果をメモリ内の正しい場所に移動 sub ecx、8;次の繰り返しのために別のバイトに切り替え shoul dはすでに0になっています mov ecx、4 mov [numha + ecx]、edx;結果をメモリ内の正しい場所に移動 sub ecx、1;次の繰り返しのために別のバイトに切り替えます – mavix

+0

これは既に解決されていますか? –

答えて

0

mov  ecx, 32 
mov  [numha+ecx], edx  ;move result to the correct spot in memory 
sub  ecx, 8     ;switch to another byte for next iteration 

mov  ecx, 4 
mov  [numha+ecx], edx  ;move result to the correct spot in memory 
sub  ecx, 1     ;switch to another byte for next iteration 
関連する問題