1 / 12

ECE291 Computer Engineering II Lecture 6

ECE291 Computer Engineering II Lecture 6. Josh Potts University of Illinois at Urbana- Champaign. Outline. Program organization Debugging hints MASM directives. Program Organization.

adriel
Download Presentation

ECE291 Computer Engineering II Lecture 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECE291Computer Engineering IILecture 6 Josh Potts University of Illinois at Urbana- Champaign

  2. Outline • Program organization • Debugging hints • MASM directives ECE291

  3. 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 ECE291

  4. 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... ECE291

  5. MASM Directives • General • TITLE my_program.asm • Includes drive:\path\filename • Definitions • DB define byte (8bits) • DW define word (16 bits) • DD define doubleword (32 bits) • EQU names a constant • Labels ECE291

  6. 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 ECE291

  7. 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 ECE291

  8. 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 ECE291

  9. 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 segmentpublic 'CODE' ; *** CODE SEGMENT *** assume cs:cseg, ds:cseg, ss:stkseg, es:nothing ECE291

  10. 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 ECE291

  11. Example Program Structure (cont.) ;====== Procedures ==================================================== KbdHandler PROC NEAR <Your code here> KbdHandler ENDP MouseHandler PROC NEAR <Your code here> MouseHandler ENDP DisplayResult PROC NEAR <Your code here> DisplayResult ENDP ECE291

  12. 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 <here comes your main procedure> CALL MPXXXXIT ; Exit to DOS MAIN ENDP CSEG ENDS END MAIN ECE291

More Related