Thursday, March 17, 2011

Displays the alphabet forward and backwards and then displays a welcome message - By Professor Ronald J. Hart

; Title: CISS 360 Demo Program
;------------------------------------------------------------
; Description: This program displays the alphabet forwards
; and backwards and then displays a welcome
; message.
;------------------------------------------------------------
; Programmer: Ron Hart
;------------------------------------------------------------
; Date/Time: Tuesday, January 11, 2011 3:54 PM
;------------------------------------------------------------

.586
.MODEL FLAT
INCLUDE console_io.h ; header file for console input/output

.STACK 4096 ; reserve 4096-byte (1024 DWORD) stack

;------------------------------------------------------------
; Input/Output Facility
;------------------------------------------------------------
;
; Macro Operand
;
; put_ch DWORD/Reg (Displays character in parameter)
;
; get_ch None (Loads character from keyboard into EAX)
;
; put_str BYTE (Displays string beginning at given address)
;
; put_i DWORD/Reg (Displays integer value in parameter)
;
; put_fp REAL4/Reg (Displays float value in parameter)
;
; get_i DWORD (Loads integer entered at keyboard into parameter)
;
; get_fp REAL4 (Loads float entered at keyboard into parameter)
;
; get_str BYTE (Loads string entered at keyboard into parameter)
;
;------------------------------------------------------------

.DATA ;****************************************************
;* Data Section *
;****************************************************

asterisks BYTE "* * * * * * * * * * * * *",10,13,0

welcome BYTE "* Welcome to CISS 360! *",10,13,0

newline DWORD 10

.CODE ;****************************************************
;* Code Section *
;****************************************************

_MainProc PROC ; start of main program

mov al, 'a' ; start with lowercase 'a'
mov ecx, 26 ; loop counter (num letter in alphabet)

do_forward:

put_ch eax ; display current character
inc eax ; add one to character value
loop do_forward ; go display next character
put_ch newline ; done, display newline
put_ch newline ; display another newline
dec eax ; decrement character value (now 'z')
mov ecx, 26 ; re-init loop counter

do_backward:

put_ch eax ; display current character
dec eax ; decrement character value
loop do_backward ; go display next character
put_ch newline ; done, display newline
put_ch newline ; display another newline
put_str asterisks ; display string of asterisks
put_str welcome ; display welcome message
put_str asterisks ; display another line of asterisks
put_ch newline ; display newline

done ; macro to display "done" message and get any key
xor eax, eax ; exit with return code 0
ret ; return

_MainProc ENDP ; end of main program

;------------------------------------------------------------

proc_name PROC ; sample procedure

push ebp ; save base pointer
mov ebp, esp ; establish stack frame

;; push registers used by this proc

;; proc code inserted here

;; pop registers used by this proc

pop ebp ; restore base pointer

ret

proc_name ENDP

;----------------------------------------------------------------------

stat_flags MACRO

fstsw ax ; FPU status word to AX
sahf ; condition code bits to flags
ENDM

;----------------------------------------------------------------------

END ; end of source code

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.