231a-ab unchanged talkToArduino.asm

From CSclasswiki
Jump to: navigation, search
;;; talkToArduino.asm
;;; D. Thiebaut
;;; 
;;;  nasm -f elf talkToArduino.asm
;;;  gcc -o talkToArduino  arduino-serial.c  talkToArduino.o
;;;

;;; ----------------------- EXTERN LABELS -----------------------
extern serialport_writebyte	; int function
extern serialport_write		; int function
extern serialport_read_until	; int function
extern displayBuffer		; int function
	
extern buf	
extern byte		
        
       ;; -------------------------
       ;; data segment
       ;; -------------------------
        section .data
msg1	db	"w d 13 1", 0
msg1len	equ	$-msg1
        
        ;; -------------------------
        ;; code area
        ;; -------------------------
        section .text
        global  asm_main
asm_main: 
	;; turn Pin 13 On 
 	mov	eax, msg1
 	mov	ecx, msg1len
 	call	copyMsg                     ;create copy of msg1 in buf, in C prog
 	call	serialport_write           ;call function in C prog
       ;; return to C program
        ret
;;; ----------------------------------------------------------------
;;; copyMsg1: puts array whose address in eax  in external buffer
;;; 	      number of bytes shoudl be in ecx.
;;; ----------------------------------------------------------------
copyMsg:
	pushad
	mov	esi, eax	; source buffer
	mov	edi, buf	; destination buffer in C program
.for	mov	al, [esi]
	mov	[edi], al
	inc	esi
	inc	edi
	loop	.for
	popad
	ret