Skip to contentSkip to conversation

code-need-to-correct

DISCUSSION ssams 3 participants 3 messages Sep 19, 2002

lore
Share & tools
lore

ssams

author
#0 lore raw

.macro sys_write

	mov $4,%eax
	mov $1,%ebx
	int $0x80
.endm
.macro sys_read
	mov $3,%eax
	mov $2,%edx
	mov $0,%ebx
	int $0x80

.endm
.data
msg1: .ascii "Masukkan Angka: "
jum_masuk:

	.byte .- msg1

satu: .ascii "Satu Lagi: "
jum_satu:
.byte .- satu
spasi: .byte 10
.bss
.lcomm input1,0
.lcomm input2,0
angka: .byte 0
.text
.globl _start
_start:

	mov $msg1,%ecx
	mov $16,%edx
	sys_write
	sys_read
	mov %eax,input1

	
	mov $satu,%ecx
	mov $11,%edx
	sys_write
	sys_read
	mov %eax,input2

tambah:

	mov (input2),%eax
	add (input1),%eax
	mov $10,%bx
	xor %ecx,%ecx
ulang:
	div %bx
	push %edx
	inc %ecx
	cmp $0,%al
	jne ulang
cetak:
	pop %edx
	add $0x30,%dx
	mov %dx,angka
	push %ecx
	mov $angka,%ecx
	mov $1,%edx
	sys_write
	pop %ecx
	loop cetak	

	mov $spasi,%ecx
	mov $1,%edx
	sys_write

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

output:

Masukkan angka: 4
Satu lagi: 5
2478030160157010470915781817.....

How to read input...?
=========================================================================
Khusus Pelanggan Telepon DIVRE 2, Tekan 166 untuk mendengarkan pesan Anda.
=========================================================================

#1 lore raw

On Thu, 19 Sep 2002 21:40:09 +0700
"ssams" <[email protected]> wrote:

re just below your '_start:' label:

linux program space, '.text' section, by standard is in read/execute memory, so you cannot input to program memory. define a label and reserve some space in the '.bss' section which is always writable - but does not contain any data at program start, filled w. <nul>-s, by the linux loader. the other commonly used section, '.data' can store nay data as well as may be written to, but also occupies it's space in the program binary, which .bss does not. just for completeness, there is also a '.rodata' setion for read-only data
- and several others, used by "ld" which are usually of no concern.

.long 0 etc will work, but no other
data, re '.fill', '.rept' in the manual.

----
.bss
inputmem:
.long 0 # as often as required
----

best,
hp

Quoted 86 lines

.macro sys_write

	mov $4,%eax
	mov $1,%ebx
	int $0x80
.endm
.macro sys_read
	mov $3,%eax
	mov $2,%edx
	mov $0,%ebx
	int $0x80

.endm
.data
msg1: .ascii "Masukkan Angka: "
jum_masuk:

	.byte .- msg1

satu: .ascii "Satu Lagi: "
jum_satu:
.byte .- satu
spasi: .byte 10
.bss
.lcomm input1,0
.lcomm input2,0
angka: .byte 0
.text
.globl _start
_start:

	mov $msg1,%ecx		<== read only memory
	mov $16,%edx
	sys_write
	sys_read		<== cannot store to .text section
	mov %eax,input1

	
	mov $satu,%ecx
	mov $11,%edx
	sys_write
	sys_read
	mov %eax,input2

tambah:

	mov (input2),%eax
	add (input1),%eax
	mov $10,%bx
	xor %ecx,%ecx
ulang:
	div %bx
	push %edx
	inc %ecx
	cmp $0,%al
	jne ulang
cetak:
	pop %edx
	add $0x30,%dx
	mov %dx,angka
	push %ecx
	mov $angka,%ecx
	mov $1,%edx
	sys_write
	pop %ecx
	loop cetak	

	mov $spasi,%ecx
	mov $1,%edx
	sys_write

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

output:

Masukkan angka: 4
Satu lagi: 5
2478030160157010470915781817.....

How to read input...?
=========================================================================
Khusus Pelanggan Telepon DIVRE 2, Tekan 166 untuk mendengarkan pesan Anda.
=========================================================================
-
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

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
#2 lore raw
Quoted 4 lines · On Thu, 19 Sep 2002 20:03:15 +0000 h-peter recktenwald <[email protected]>…

On Thu, 19 Sep 2002 21:40:09 +0700
"ssams" <[email protected]> wrote:

re just below your '_start:' label:

...error, didn't see that i/o already in .bss.
so, i won't be able to help, further, too.

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