| |||||||||||||||||
Machine Problem 1: Illini Union Bank
IntroductionThe University has decided that its students don't owe enough money. In order to rectify this problem, a new financial institution by the name of Illini Union Bank has been founded. In order to cut development costs, administrators have decided to use unwitting engineering students to write the bank's code. ![]() Problem DescriptionThe bank ledger allows ten entries to be recorded. Each entry records three fields of information: whether the transaction is a deposit or withdrawal, the amount of the transaction, and a memo tag that indicates the nature of the transaction. All of this information is stored in three bytes -- the first contains the deposit/withdrawal flag and memo tag, and the other two hold the transaction amount as a 16-bit positive integer. (That is, withdrawal amounts are still stored as a positive value!) The bits of the first byte correspond to the following. For a valid entry, only one of bits 1 through 7 is a 1.
The functions you will be writing will display information to the screen, interpret keyboard input, and manipulate the entry array. The program's main loop (which is provided and you need not write) repeatedly shows the main menu and calls appropriate functions as necessary. When the user chooses to quit or the entry array becomes full, the program will display the account summary one last time and then output a message depending upon the account's balance. MP 1 Program AssignmentYour job in this assignment will be to provide rewrites of certain precompiled library routines described below. A working MP will be provided for you to get a feel for the program, as well as an .ASM file with calls to the pre-written library routines. You should go through the routines one by one, replacing these calls with your own code. The program can be run by typing mp1 at the command prompt.
Brief Intro to PUSH and POP
Hints
SubroutinesThis assignment has eight procedures. You will receive credit by replacing each of these eight procedures listed below with your own code. Assume these function call library routines such as dspmsg as needed.
Procedure
Final Steps1. Demonstrate your MP1.EXE to a TA. You may be asked to recompile and demo the program. Your program must work with all given input. 2. Be prepared to answer questions about any aspect of the operation of your program. The TAs will not accept an MP if you cannot fully explain your code and your implementation. Delayed MPs will be subject to late penalties as described in the course syllabus (10% pts per day). 3. The TA will complete the code submission procedure. MP1.ASM (program framework)
; MP1 - Your Name - Today's Date
;
;
; Josh Potts, Fall 2001
; Guest Author: George Lu
; University of Illinois, Urbana-Champaign
; Dept. of Electrical and Computer Engineering
;
; Version 1.0
BITS 16
;====== SECTION 1: Define constants =======================================
CR EQU 0Dh
LF EQU 0Ah
BEL EQU 07h
MAX_ENTRIES EQU 10
;====== SECTION 2: Declare external procedures ============================
; These are functions from lib291
EXTERN kbdine, dspout, dspmsg, dosxit,ascbin,binasc
; You will be writing your own versions of these functions
EXTERN _libDisplayEntry, _libDisplayAllEntries, _libDisplayAcademicEntries
EXTERN _libInterpretAmount, _libInterpretTag, _libAddDeposit
EXTERN _libAddWithdraw, _libDisplayTotal, mp1xit
; The _lib functions need these to work properly
GLOBAL MainHeader, MainMenu, AmountMenu, TagMenu, msg_Total, msg_NoEntries
GLOBAL msg_Invalid, msg_Deposit, msg_Withdraw, msg_Books, msg_Supply
GLOBAL msg_Academic, msg_Rent, msg_Food, msg_Entertain, msg_Other
GLOBAL msg_CRLF, msg_Cookie, msg_BigDebt, msg_SmallDebt, msg_SmallPlus
GLOBAL msg_BigPlus
GLOBAL _DisplayMainMenu, _DisplayAmountMenu, _DisplayTagMenu
GLOBAL EntryArray, NumEntries, Buffer
GLOBAL _DisplayEntry, _InterpretAmount, _InterpretTag
;====== SECTION 3: Define stack segment ===================================
SEGMENT stkseg STACK ; *** STACK SEGMENT ***
resb 64*8
stacktop:
;====== SECTION 4: Define code segment ====================================
SEGMENT code ; *** CODE SEGMENT ***
;====== SECTION 5: Declare variables for main procedure ===================
EntryArray resb (3*MAX_ENTRIES)
NumEntries db 0
Buffer resb 7
MainHeader db CR, LF, CR, LF, 'Blah. Witty Menu Title Here.'
db CR, LF, ' Current Number of Entries: $'
MainMenu db CR, LF, '------------------------------------'
db CR, LF, ' a) Make a deposit'
db CR, LF, ' b) Make a withdrawal'
db CR, LF, ' c) Display all entries'
db CR, LF, ' d) Display academic-related entries'
db CR, LF, ' e) Exit'
db CR, LF, CR, LF, 'Selection: $'
AmountMenu db CR, LF
db CR, LF, 'Select Amount of Transaction:'
db CR, LF, '-----------------------------'
db CR, LF, ' a) 1 b) 4'
db CR, LF, ' c) 16 d) 64'
db CR, LF, ' e) 256 f) 1024'
db CR, LF, ' g) 4096'
db CR, LF, CR, LF, 'Selection: $'
TagMenu db CR, LF
db CR, LF, 'Select Transaction Memo:'
db CR, LF, '------------------------'
db CR, LF, ' a) Books'
db CR, LF, ' b) School Supplies'
db CR, LF, ' c) Other Academic'
db CR, LF, ' d) Rent'
db CR, LF, ' e) Food'
db CR, LF, ' f) Entertainment'
db CR, LF, ' g) Other'
db CR, LF, CR, LF, 'Selection: $'
msg_Total db CR, LF, CR, LF, ' Account Balance: $'
msg_NoEntries db CR, LF, 'There are no entries!$'
msg_Invalid db CR, LF, '*** Invalid Selection! Operation aborted! ***$'
msg_Deposit db CR, LF, 'Deposit $'
msg_Withdraw db CR, LF, 'Withdraw $'
msg_Books db ' Books$'
msg_Supply db ' School Supplies$'
msg_Academic db ' Other Academic$'
msg_Rent db ' Rent$'
msg_Food db ' Food$'
msg_Entertain db ' Entertainment$'
msg_Other db ' Other$'
msg_CRLF db CR, LF, '$'
msg_Cookie db CR, LF, CR, LF
db 'Leaving the bank, you stop by a Chinese restaurant', CR, LF
db 'for food. While waiting for your order, you are', CR, LF
db 'presented with a fortune cookie. You break it open', CR, LF
db 'and the message inside reads...', CR, LF, CR, LF, '$'
msg_BigDebt db 'A fortuitious fortune may fix your financial flaws.'
db CR, LF, ' Lucky numbers: 1, 2, 8, 9, 23, 43, 45'
db CR, LF, '$'
msg_SmallDebt db 'You are in debt. You are in ECE291. Get used to both.'
db CR, LF, '$'
msg_SmallPlus db 'You have survived the horrors of IUB. Enjoy your rest...'
db CR, LF, ' Until next semester.', CR, LF, '$'
msg_BigPlus db 'You have too much money for a college student. The'
db CR, LF, ' IRS and FBI have been contacted.', CR, LF, '$'
;====== SECTION 6: Program initialization =================================
..start:
mov ax, cs ; Initialize Default Segment register
mov ds, ax
mov ax, stkseg ; Initialize Stack Segment register
mov ss, ax
mov sp, stacktop ; Initialize Stack Pointer register
;====== SECTION 7: Main procedure =========================================
MAIN:
.MainLoop
cmp byte [NumEntries], MAX_ENTRIES
jae .End
call _DisplayMainMenu
cmp al, 'a'
je .AddDeposit
cmp al, 'b'
je .AddWithdraw
cmp al, 'c'
je .DisplayAll
cmp al, 'd'
je .DisplayAcad
cmp al, 'e'
je .End
mov dx, msg_Invalid
call dspmsg
jmp .MainLoop
.AddDeposit
call _AddDeposit
jmp .MainLoop
.AddWithdraw
call _AddWithdraw
jmp .MainLoop
.DisplayAll
call _DisplayAllEntries
jmp .MainLoop
.DisplayAcad
call _DisplayAcademicEntries
jmp .MainLoop
.End
call _DisplayAllEntries
call _DisplayTotal
call mp1xit
;--------------------------------------------------------------------------
; DisplayMainMenu
; Inputs: none
; Outputs: al = selection from keyboard
; Calls: dspmsg, binasc, kbdine
;--------------------------------------------------------------------------
_DisplayMainMenu
push bx ; All used registers except ax are pushed because
push cx ; only ax returns information. (Notice: You can't
push dx ; push or pop an 8-bit register.)
mov dx, MainHeader
call dspmsg ; Display menu header
xor ax, ax
mov al, [NumEntries]
mov bx, Buffer
call binasc ; Call binasc to convert a binary number into ASCII
mov dx, bx
call dspmsg ; Display the converted number
mov dx, MainMenu
call dspmsg ; Display the rest of the menu
call kbdine ; Wait for keyboard input
pop dx ; Pop all pushed registers -- notice the order
pop cx
pop bx
ret
;--------------------------------------------------------------------------
; DisplayAmountMenu
; Inputs: none
; Outputs: al = selection from keyboard
; Calls: dspmsg, binasc, kbdine
;--------------------------------------------------------------------------
_DisplayAmountMenu
push dx
mov dx, AmountMenu
call dspmsg
call kbdine
pop dx
ret
;--------------------------------------------------------------------------
; DisplayTagMenu
; Inputs: none
; Outputs: al = selection from keyboard
; Calls: dspmsg, binasc, kbdine
;--------------------------------------------------------------------------
_DisplayTagMenu
push dx
mov dx, TagMenu
call dspmsg
call kbdine
pop dx
ret
;-------------------------------------------------------------------------
; DisplayEntry
;-------------------------------------------------------------------------
_DisplayEntry
call _libDisplayEntry
ret
;-------------------------------------------------------------------------
; DisplayAllEntries
;-------------------------------------------------------------------------
_DisplayAllEntries
call _libDisplayAllEntries
ret
;-------------------------------------------------------------------------
; DisplayAcademicEntries
;-------------------------------------------------------------------------
_DisplayAcademicEntries
call _libDisplayAcademicEntries
ret
;-------------------------------------------------------------------------
; InterpretAmount
;-------------------------------------------------------------------------
_InterpretAmount
call _libInterpretAmount
ret
;-------------------------------------------------------------------------
; InterpretTag
;-------------------------------------------------------------------------
_InterpretTag
call _libInterpretTag
ret
;-------------------------------------------------------------------------
; AddDeposit
;-------------------------------------------------------------------------
_AddDeposit
call _libAddDeposit
ret
;-------------------------------------------------------------------------
; AddWithdraw
;-------------------------------------------------------------------------
_AddWithdraw
call _libAddWithdraw
ret
;-------------------------------------------------------------------------
; DisplayTotal
;-------------------------------------------------------------------------
_DisplayTotal
call _libDisplayTotal
ret
|
| Fall 2001 |