ece291 computer engineering ii lecture 6 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
ECE291 Computer Engineering II Lecture 6 PowerPoint Presentation
Download Presentation
ECE291 Computer Engineering II Lecture 6

Loading in 2 Seconds...

play fullscreen
1 / 12

ECE291 Computer Engineering II Lecture 6 - PowerPoint PPT Presentation


  • 106 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'ECE291 Computer Engineering II Lecture 6' - adriel


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
ece291 computer engineering ii lecture 6

ECE291Computer Engineering IILecture 6

Josh Potts

University of Illinois at Urbana- Champaign

outline
Outline
  • Program organization
  • Debugging hints
  • MASM directives

ECE291

program organization
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

debugging hints
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

masm directives
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

masm directives1
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

masm directives cont
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

example program structure
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

example program structure cont
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

example program structure cont1
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

example program structure cont2
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

example program structure cont3
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