Re: Question about jumps
- From: "Dragontamer" <prtiglao@xxxxxxxxx>
- Date: 30 Aug 2006 10:37:45 -0700
Dragontamer wrote:
Markus Pitha wrote:
Thanks for the tipps.
As I read in AoA that shifting a byte to the left would multiply the
operand by two, I was in mood to try it out. But unfortunately it didn't
work. I have no clue why, but my following code read a number from stdin,
but doesn't display any output. What's wrong here?
segment .code
msg1 db "Enter a number: ", 0
len1 equ $-msg1
segment .bss
nmbr resb 8
segment .text
global _start
_start:
mov eax, 4 ;write
mov ebx, 1
mov ecx, msg1
mov edx, len1
int 0x80
mov eax, 3 ;read
mov ebx, 0
mov ecx, nmbr
mov edx, 8
int 0x80
mov eax, nmbr
shl eax, 1 ; nmbr * 2
mov ecx, eax ; mov it to ecx
mov eax, 4
mov ebx, 1
mov edx, 8
int 0x80
mov eax, 1 ; sys_exit
mov ebx, 0
int 0x80
You need to convert the number into a string before you can
display it.
I suggest using the C stdlib (ssprintf or itoa if its in your standard
library) or HLA's library so you can print integers directly.
If you want to do it yourself... well; just allocate the memory
in the bss section or a code section, and erm; convert it into
ascii. What else to say? You can do it easily with a recursive
function. Modulo (% in C and Java IIRC) is combined with the
div operator. When you do a divide in Assembly... bah; just
read the docs/AoA whatever.
--Dragontamer
And don't forget to do atoi (or your own homebuilt atoi) to
convert the string into an integer.
You can't just operate on strings. You have to convert into
integers before you can add, subtract, etc. etc.
--Dragontamer
.
- References:
- Question about jumps
- From: Markus Pitha
- Re: Question about jumps
- From: Evenbit
- Re: Question about jumps
- From: Markus Pitha
- Re: Question about jumps
- From: Dragontamer
- Question about jumps
- Prev by Date: Re: Question about jumps
- Next by Date: Re: Question about jumps
- Previous by thread: Re: Question about jumps
- Next by thread: Re: Question about jumps
- Index(es):
Relevant Pages
|