CSC231 Teller1.asm

From dftwiki3
Jump to: navigation, search

--D. Thiebaut (talk) 12:57, 14 October 2015 (EDT)


<showafterdate after="20170307" before="20170601">

Source


;;; ; teller1.asm
;;; ; D. Thiebaut
;;; ;
;;; ; Demo of a teller machine program.
;;; ; To assemble, link, and run:
;;; ;     nasm -f elf  teller.asm
;;; ;     ld -melf_i386 -o teller teller.o 231Lib.o
;;; ;     ./teller
;;; ;                

;;;  extern functions that will be linked to this program
;;; ; contained in 231Lib.asm

extern  _printDec
extern  _printString
extern  _println
extern  _getInput

;;; ------------------------------------------------------
;;; DATA SECTION
;;; ------------------------------------------------------        
		section	.data
amount          dd      139
no20s           dd      0
no10s           dd      0
no5s            dd      0
no1s            dd      0

msg             db      "sum = "
MSGLEN          equ     $-msg        

;;; ------------------------------------------------------
;;; CODE SECTION
;;; ------------------------------------------------------        
		section	.text
		global	_start
_start:	

;;; print message
                mov     edx, 0
                mov     eax, dword[amount]

                mov     ebx, 20
                div     ebx
                mov     dword[no20s],eax
                mov     eax, edx
                mov     edx, 0

                mov     ebx, 10
                div     ebx
                mov     dword[no10s],eax
                mov     eax, edx
                mov     edx, 0

                mov     ebx, 5
                div     ebx
                mov     dword[no5s], eax
                mov     dword[no1s], edx

                mov     eax, dword[no20s]
                call    _printDec
                call    _println
                mov     eax, dword[no10s]
                call    _printDec
                call    _println
                mov     eax, dword[no5s]
                call    _printDec
                call    _println
                mov     eax, dword[no1s]
                call    _printDec
                call    _println
        

;;; exit
		mov	ebx, 0
		mov	eax, 1
		int	0x80

;;; sum: gets 2 ints in eax and ebx and returns the sum in
;;; eax.
sum:            add     eax, ebx,
                ret


Output


6
1
1
4



</source>