Re: increment values from stdin





Hello,



thanks for your explanations. There is still something different I don't

understand. I tried to use a different method for writing out numbers

bigger than 9 with shifting the bits to the left. First of all, I tried it

with reading a single char from stdin and I tried to "add" a "B", so the

output should be "AB". It should be 16 bit:



01000001......A

01000010......B



but that doesn't work because I get this output:



$ ./movetest

Enter a char: A

B



$ ./movetest

Enter a char: 123456789

B56789



It seems that the first 4 bytes are replaced by the 'B' but how does this

happen? I don't move 4 bytes anywhere.

Here is my test program:



segment .data

prompt1 db "Enter a char: ", 0

len equ $-prompt1



segment .bss

input1 resb 16



segment .text

global _start



_start:

mov eax, 4 ; write system call

mov ebx, 1 ; stdout (=1)

mov ecx, prompt1

mov edx, len

int 0x80 ; syscall



mov eax, 3 ; read system call

mov ebx, 0 ; stdin(0)

mov ecx, input1

mov edx, 16 ; input length in byte

int 0x80



;move it to the left and add a 'B'

mov ecx, [input1]

shl ecx, 8 ;move it 8 bytes to the left

mov ecx, 'B'

mov [input1], ecx





;output

mov eax, 4 ; write system call

mov ebx, 1 ; stdout (=1)

mov ecx, input1

mov edx, 16

int 0x80



mov eax, 1 ; kernel exit

mov ebx, 0

int 0x80



What did I do wrong this time?



Thanks,

Markus



.



Relevant Pages