Skip to contentSkip to conversation

code_for_integer_printing

DISCUSSION ssams 2 participants 3 messages Sep 6, 2002 – Sep 19, 2002 1 message not in the archive

lore
Share & tools
lore

ssams

author
#0 lore raw

i want to ask about a little code bellow...
i build this code for print some integer value.. i think is easy for doing but after i do some fungtion below
i did not find ionteger output.
so how is function to do it..?

this is my code, i hope you help me..? thank's before..

.macro cetak # macro for printing

	xor %eax,%eax
	mov $1,%ebx
	mov $4,%eax
	int $0x80
.endm
.data
promt1:
	.byte 65
.text
.globl _start
_start:
	mov $promt1,%eax 	#eax will divided
	mov $10,%ebx		#ebx is divident
	xor %ecx,%ecx
ulangi:
	xor %edx,%edx
	div %ebx		#eax : ebx
	push %edx		# save remainder
	inc %ecx
	cmp $0 ,%eax
	jne ulangi

	mov $3,%ecx
ulang_cetak:
	push %ecx
	pop %edx		#take point
	add $0 ,%dl		#convert to ascii
	mov %edx,%ecx		#for printing
	mov $1,%edx
	cetak			#print
	pop %ecx
	dec %ecx
	jnz ulang_cetak

	movl $1,%eax	#exit
	movl $0,%ebx
	int  $0x80

--------------------- Yang Mudah dan Menghibur ----------------------------

Hosting menjadi mudah dan murah hanya di PlasaCom. Klik http://idc.plasa.com

F1 Mania!! Ikuti F1 Game di Obelix Game Corner di http://www.plasa.com/infotel/f1.html

---------------------------------------------------------------------------------------

#1 lore raw

On Sat, 07 Sep 2002 00:06:03 +0700
"ssams" <[email protected]> wrote:

	[...]
Quoted 4 lines

ulang_cetak:
push %ecx
pop %edx #take point
add $0 ,%dl #convert to ascii

	add $'0,dl
or
	add $48,dl
Quoted 7 lines
	mov %edx,%ecx		#for printing
	mov $1,%edx
	cetak			#print
	pop %ecx
	dec %ecx
	jnz ulang_cetak

regards,
hp

Signature · 6 lines
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml en/de
    software patents  http://petition.eurolinux.org/pr/pr17.html
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
In reply to a message not in the archive

On Mon, 16 Sep 2002 12:31:26 +0700
"ssams" <[email protected]> wrote:

i do not re-write the code for you:) but, i hope that my annotations will help. i'd suggest you try getting through my syscalls intro at
http://www.lxhp.in-berlin.de/lhpsyscal.html
but, those syscalls aren't all that simple; try verifying what happens by following the rsp. source files. could aid a lot to understanding. if you find it difficult to connect to the syscalls pages i could send you the complete colletion as an archive, by email or, you might get it yourself by
http://www.lxhp.in-berlin.de/lhpsysc-html.tar.bz2

best,
hp

Quoted 6 lines

.macro cetak # macro for printing
xor %eax,%eax
mov $1,%ebx
mov $4,%eax
int $0x80
.endm

essential: syscalls read/write (and many others) always use an address of where the data are which you want to operate on and a count of bytes of the length of that sequence of data. which for 'read' and 'write' means that with ECX you pass the #address# of your text and, with EDX the number of bytes to receive or send.

so, for instance, you could modify the macro to
.macro cetak # all regs but EAX, EBX preserved

	pushl %ecx	# print the register value itself, 
	movl %esp,%ecx	# this is your temporary buffer address
	movl $1,%ebx	# Linux "stdout"
	movl $4,%eax	# sys_write
	int $0x80	# execute...
	cmpl $0xffff0001,%eax # optional: NC in EFLAGS if EAX error code
	popl %ecx	# remove temp buffer = restore stack, and restore ECX
.endm
# or, restore stack, e.g. w.  "addl $4,%esp" which modifies EFLAGS
# or, preserve error flags w. "leal 4(%esp),%esp"
# note that the above error test is valid for #all# syscalls.

btw, you could save typing those "%"s (they are often required if AS used for the GCC backend, though) with:
.att_syntax no_prefix
at top of your assembly text.

Quoted 41 lines

.data
promt1:
.byte 65
.text
.globl _start
_start:

(quoted diff) +0 -0
 	mov $promt1,%eax #eax will divided
 	mov $10,%ebx #ebx is divident
 	xor %ecx,%ecx
 
 ulangi:
 	xor %edx,%edx
 	div %ebx #eax : ebx
 	push %edx # save remainder
 	inc %ecx
 	cmp $0 ,%eax
 	jne ulangi
 
	mov $3,%ecx
	 ulang_cetak:
(quoted diff) +0 -0
 	push %ecx
 	pop %edx #take point
 	add $48 ,%dl 	#convert to ascii i've try add with $'0' to

#but it same no output with it

(quoted diff) +0 -0
 	mov %edx,%ecx #for printing
 	mov $1,%edx
 	cetak #print
 	pop %ecx
 	dec %ecx
 	jnz ulang_cetak
 
	movl $1,%eax #exit
	 movl $0,%ebx
	int $0x80

regards,
ssams

=========================================================================
Khusus Pelanggan Telepon DIVRE 2, Tekan 166 untuk mendengarkan pesan Anda.
=========================================================================

Signature · 1 line
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml en/de