//---------------------------------------------------------------- // manydots.s // // This is an assembly language program that runs under the // Linux operating system, but without calling functions in // the standard C runtime library. Instead, it makes calls // directly to the Linux kernel, to perform console i/o and // then to exit back to the command-shell when finished. // // assemble with: $ as manydots.s -o manydots.o // and link with: $ ld manydots.o base10io.o -o manydots // execute using: $ ./manydots // // NOTE: This program is linked with a separately assembled // object-file (named 'base10io.o'). // // programmer: ALLAN CRUSE // written on: 09 MAR 2004 // revised on: 04 FEB 2007 //---------------------------------------------------------------- # symbolic names for device and system-call ID-numbers .equ dev_STDIN, 0 # device-ID for keyboard .equ dev_STDOUT, 1 # device-ID for display .equ sys_EXIT, 1 # service-ID for 'exit' .equ sys_READ, 3 # service-ID for 'read' .equ sys_WRITE, 4 # service-ID for 'write' .section .data prompt: .ascii "How many dots do you want to see? " length: .int . - prompt # length of this message count: .int 0 # will hold the dot-count dot: .ascii "." # ascii code for the dot newln: .ascii "\n" # ascii code for newline answer: .space 16 # will hold keybd input .section .text _start: # prompt the user for input movl $sys_WRITE, %eax # system-call ID-number movl $dev_STDOUT, %ebx # device's ID-number leal prompt, %ecx # buffer-address mov length, %edx # buffer-length int $0x80 # enter the kernel # obtain the user's response movl $sys_READ, %eax # system-call ID-number movl $dev_STDIN, %ebx # device's ID-number leal answer, %ecx # buffer-address mov $16, %edx # buffer-length int $0x80 # enter the kernel # convert the input-string to an integer lea answer, %esi call asc2eax mov %eax, count # loop to show the requested number of dots movl count, %ecx # setup the loop-count jecxz .L3 # zero? skip past loop .L2: pushl %ecx # preserve loop-count movl $sys_WRITE, %eax # system-call ID-number movl $dev_STDOUT, %ebx # device's ID-number leal dot, %ecx # buffer-address movl $1, %edx # buffer-length int $0x80 # enter the kernel popl %ecx # restore loop-count loop .L2 .L3: # advance the cursor to the beginning of the next line movl $sys_WRITE, %eax # system-call ID-number movl $dev_STDOUT, %ebx # device's ID-number leal newln, %ecx # buffer-address movl $1, %edx # buffer-length int $0x80 # enter the kernel # yield control back to the operating system movl $sys_EXIT, %eax # system-call ID-number movl $0, %ebx # zero is return-code int $0x80 # enter the kernel .global _start # entry-point is visible .end # no more to be assembled