• Problem 1 : Table Lookup Functions ; -- External Functions (Use these freely) -- extrn dspmsg near ; Input : DX = message pointer extrn random near ; Output : AX = Random Integer between 0 .. 2^15-1 ; -- Variable Section -- Title1 db 'Twister','$' Title2 db 'Field of Debris','$' Title3 db 'Four Weddings and a Funnel','$' Title4 db 'Roofless in Seattle','$' Title5 db 'Splintered Bridges of Madison County','$' Titletable dw offset Title1, offset Title2, offset Title3, offset Title4, offset Title5 ; -- Code Section -- ChooseTitle PROC Near ; Preserve registers AX,BX,DX call random ; Returns AX=0..2^16-1 in AX mov DX, 0 mov BX, 5 div BX ; Mod by 5 to get Random value between 0..4 mov BX, DX shl BX, 1 ; Multiply by 2 to index word table mov DX, TitleTable[BX] ; Fetch pointer using Table Lookup call DspMsg ; Print the message ret ; Restore registers AX,BX,DX ChooseTitle ENDP
  • Problem 2 : Text-Mode Video Graphics ColorPrint PROC NEAR ; DI=Pointer to String ; DH=Row ; DL=Column mov AX, 0B800h mov ES, AX ; Set Video Text Segment (Assume already in text mode) mov SI, DI ; Store string pointer in SI (not DI) mov AL, 80 mul DH ; Calculate Postion = Row * 80 + Column mov DH, 0 add AX, DX ; Add column mov DI, AX shl DI, 1 ; Screen offset = 2 (80*row + col) CLoop1: mov AL, 4 ; Start with attribute = Red cmp [SI], '$' ; Test for completion je CDone CLoop2: and ES:[DI], 11110000b ; Write color Attribute byte to screen or ES:[DI], AL mov AH, [SI] mov ES:[DI+1], AH ; Write Data byte to screen add SI, 1 add DI, 2 ; Prepare for next data shr al, 1 ; Alternate colors (4,2,1) cmp al, 0 je CLoop1 jmp CLoop2 CDone: ret ColorPrint ENDP
  • Problem 3: ISRs
    • Table Values
      • Task A: Period=5ms, CPU load=40% (Period=inverse Freq)
      • Task B: Run Time=4ms, Period=10ms
      • Task C: Freq=10Hz, CPU load=1%
    • Total CPU Load=81% (Sum of process load)
    • Preemptive Case
      • Task A: 2ms (interrupts any other process): AA
      • Task B: 8ms (interrupted by A twice): AABBBAAB
      • Task C: 9ms (interrupted by A twice and B once): AABBBAABC
    • Non-Preemptive Case
      • Task A: 6ms (task B runs first): BBBBAA
      • Task B: 7ms (task C runs first, then A): CAABBBB
      • Task C: 9ms (task A twice, B once): AABBBBAAC or BBBBAAAAC

  • Problem 4 : String Operations StrOld db 'ECE291 Is The Greatest Class In This Universe.','$' StrNew db 50 dup (?) CreateMessage PROC NEAR ; preserve registers (PUSH AX,SI,DI,ES) mov AX, DS mov ES, AX ; set ES=DS mov SI, offset StrOld+32 ; SI points to "This" in StrOld mov DI, offset StrNew ; DI points to start of StrNew CLD ; Auto-increment mov CX, 5 rep movsb ; copy "This" and following space mov SI, offset StrOld+7 ; SI points to "Is" in StrOld mov CX, 22 rep movsb ; copy "Is The Greatest Class" mov AL, '!' mov CX, 6 rep stosb ; append "!!!!!!" mov AL, '$' ; End string marker stosb ; restore registers CreateMessage ENDP

  • Problem 5: Algorithms / Data Structure
    • (9 Entries) * (2 Bytes for X + 1 Byte for Counter) = 27 Bytes
    • (Relevant to Spring 97): Hanoi: N=1:1, N=2:3, N=3:7, N=5,15
    • (Relevant to Spring 97): Lander: A=T-G, V=Vo+A*t, Y=Yo+V*t
      Thus Y=(T-G)+Vo+Yo
    • Macros expand to code. Unless base case value is known at compile time, recursion cannot be expanded.

  • Problem 6: Hardware Devices
    • Horizontal Line MOV AX,0A000h MOV ES,AX MOV DI,320 MOV CX,160 MOV AX,0202h CLD REP STOSW
    • Video Card
      • Colors=2^15
      • Simultaneous colors=16 (palette)
      • VRAM=500kByte
      • 16 colors (limited by palette)
    • Number of IN operations is proportional to polling time, T. T=RC is a capacitive-resistive time constant. T=RC is a linear function because C is constant. R varies linearly with position. Thus number of INs is linearly proportional to position.