Download presentation
Presentation is loading. Please wait.
Published byMeagan Williams Modified over 9 years ago
1
EENG4005 Outline Program organization Debugging hints MASM directives
2
EENG4005 Program Organization Create block structure and/or pseudocode on paper to get a clear concept of program control flow and data structures Break the total program into logical procedures/macros Use jumps, loops, etc. where appropriate Use descriptive names for variables –noun_type for types –nouns for variables –verbs for procedures/functions
3
EENG4005 Debugging Hints Good program organization helps Programs do not work the first time Strategy to find problems –Use DEBUG breakpoints to check program progress –Use COMMENT to temporarily remove sections of code –"print" statements announce milestones in program Test values/cases –Try forcing registers/variables to test output of a procedure –Use "print" statements to display critical data Double-check your own logic (Did you miss a special case?) Try a different algorithm, if all else fails...
4
EENG4005 MASM Directives General –TITLEmy_program.asm Includesdrive:\path\filename Definitions –DB define byte (8bits) –DWdefine word (16 bits) –DDdefine doubleword (32 bits) –EQUnames a constant Labels
5
EENG4005 MASM Directives Macros –Instead of using procedures, which require both stack and time resources, macros are fast and flexible –Advantages: speed; no call instruction readability - easier to understand program function –Drawbacks - space using the MACRO multiple times duplicates the code tricky to debug (in particular when you have nested MACROs) Procedures –“name” PROC NEAR/FAR –ENDP
6
EENG4005 MASM Directives (cont.) References to procedures –EXTERN“name” NEAR/FAR/BYTE/WORD –PUBLIC “ name” Segment definition –SEGMENT “name” PUBLIC/STACK –ENDS Segment register “Hooks” –ASSUME CS:CSEG; DES:CSEG; SS:STACK
7
EENG4005 Example Program Structure TITLE ECE291:MPXXX COMMENT * In this MP you will develop program which take input from the keyboard………… * ;====== Constants ==================================================== ;ASCII values for common characters CR EQU 13 LF EQU 10 ESCKEY EQU 27 ;====== Externals ==================================================== ; -- LIB291 Routines extrn dspmsg:near, dspout:near, kbdin:near extrn rsave:near, rrest:near, binasc:near
8
EENG4005 Example Program Structure (cont.) ; ==== LIBMPXXX Routines (Your code will replace calls to these functions) extrn LibKbdHandler:near extrn LibMouseHandler:near extrn LibDisplayResult:near extrn MPXXXXIT:near ;====== Stack ======================================================== stkseg segment stack ; *** STACK SEGMENT *** db 64 dup ('STACK ') ; 64*8 = 512 Bytes of Stack stkseg ends ;====== Begin Code/Data ============================================== cseg segment public 'CODE' ; *** CODE SEGMENT *** assume cs:cseg, ds:cseg, ss:stkseg, es:nothing
9
EENG4005 Example Program Structure (cont.) ;====== Variables ==================================================== inputValid db 0 ; 0: InputBuffer is not ready ; 1: InputBuffer is ready ;-1: Esc key pressed operandsStr db 'Operands: ','$' OutputBuffer db 16 dup(?),'$' ; Contains formatted output ; (Should be terminated with '$') MAXBUFLENGTH EQU 24 InputBuffer db MAXBUFLENGTH dup(?),'$' ; Contains one line of user input include graphData.dat ; data PUBLIC OutputBuffer, inputValid, operandsStr PUBLIC graphData
10
EENG4005 Example Program Structure (cont.) ;====== Procedures ==================================================== KbdHandler PROC NEAR KbdHandler ENDP MouseHandler PROC NEAR MouseHandler ENDP DisplayResult PROC NEAR DisplayResult ENDP
11
EENG4005 Example Program Structure (cont.) ;====== Main Procedure ================================================ MAIN PROC FAR MOV AX, CSEG ; Use common code and data segment MOV DS, AX MOV AX, 0B800h ; Use extra segment to access video screen MOV ES, AX CALL MPXXXXIT ; Exit to DOS MAIN ENDP CSEG ENDS END MAIN
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.