ECE291 Computer Engineering II Lecture 6 - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

ECE291 Computer Engineering II Lecture 6

Description:

Create block structure and/or pseudocode on paper to get a clear concept of ... Double-check your own logic (Did you miss a special case? ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 13
Provided by: ZbigniewK9
Category:

less

Transcript and Presenter's Notes

Title: ECE291 Computer Engineering II Lecture 6


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

2
Outline
  • Program organization
  • Debugging hints
  • MASM directives

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

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

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

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

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 CSCSEG DESCSEG SSSTACK

8
Example Program Structure
  • TITLE ECE291MPXXX
  • 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 dspmsgnear, dspoutnear, kbdinnear
  • extrn rsavenear, rrestnear, binascnear

9
Example Program Structure (cont.)
  • LIBMPXXX Routines (Your code will replace
    calls to these functions)
  • extrn LibKbdHandlernear
  • extrn LibMouseHandlernear
  • extrn LibDisplayResultnear
  • extrn MPXXXXITnear
  • Stack
  • stkseg segment stack
    STACK SEGMENT
  • db 64 dup ('STACK ') 648
    512 Bytes of Stack
  • stkseg ends
  • Begin Code/Data
  • cseg segment public 'CODE'
    CODE SEGMENT
  • assume cscseg, dscseg, ssstkseg,
    esnothing

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

11
Example Program Structure (cont.)
  • Procedures
  • KbdHandler PROC NEAR
  • ltYour code heregt
  • KbdHandler ENDP
  • MouseHandler PROC NEAR
  • ltYour code heregt
  • MouseHandler ENDP
  • DisplayResult PROC NEAR
  • ltYour code heregt
  • DisplayResult ENDP

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
  • lthere comes your main proceduregt
  • CALL MPXXXXIT Exit
    to DOS
  • MAIN ENDP
  • CSEG ENDS
  • END MAIN
Write a Comment
User Comments (0)
About PowerShow.com