7. Compute value of total. Hint: make computation on a register such as ax, and
then move result into the total variable. 8. Assemble the code using TASM. At the
...
X86 Assembly Language Programming for the PC (EET-241 / ENGR-275)
Walter Lara
Lab #3: Simple Arithmetic Operations Overview: In this lab you will develop a program that performs simple arithmetic operations such as addition and subtraction. Requirements The program should allow you to enter 3 decimal signed numbers (a,b,c) using the keyboard. Then, it should perform the following formula: total = (-a) + b – c Finally, it should display the value of total to the screen. Utility procedures will be provided to perform the required I/O operations. Your job is to do the arithmetic.
Directions 1. Download & extract the utility files (utils.asm & utils.inc) into c:\ . 2. Create an assembly language code file named c:\lab3.asm using Notepad++.
3. Type in the following code skeleton: include utils.inc
;include utility functions declarations
.model
small
;specify small memory model
.stack
200h
;specify a stack size of 512 bytes
.data msg_total msg_a a total .code start:
db db dw dw
"Total is: ",'$' "Enter value of a: ",'$' ? ?
X86 Assembly Language Programming for the PC (EET-241 / ENGR-275) mov ax,@data mov ds,ax
Walter Lara
;set-up ds to be able to access our data
;ask user for value of a mov ah,09h lea dx,msg_a int 21h
;Use DOS service 09h to print msg_a
call get_number mov a,ax
;Use utility procedure to get number ;result is returned on ax, save it
;TODO: ask user for b ;TODO: ask user for c ;TODO: compute total mov ah,09h lea dx,msg_total int 21h
;Use DOS service 09h to print msg_total
mov ax,total ;Use utility procedure to display total call print_number exit: mov ax,4c00h int 21h end start
;Invoke DOS interrupt 21h, service 4ch ;to exit program ;tell assembler to finish
4. Declare variables b & c in the data section (all 16-bit). Hint: take a look at how variable a is declared. 5. Create prompt messages for the b & c operands (name them msg_b & msg_c respectively) Hint: take a look at how variable msg_a is created. 6. Display prompt messages and get User input value for the b & c operands Hint: take a look at how this is done for the a operand. 7. Compute value of total. Hint: make computation on a register such as ax, and then move result into the total variable. 8. Assemble the code using TASM. At the DOS prompt type: C:\>tasm /l /zi utils.asm C:\>tasm /l /zi lab3.asm
X86 Assembly Language Programming for the PC (EET-241 / ENGR-275)
Walter Lara
The “/l” switch tells the assembler to generate an output listing file (named util.asm & lab3.lst) while the “/zi” tells it to generate symbolic information needed for the linker. Note: MASM32 equivalent command is: C:\>ml /c /Fl utils.asm C:\>ml /c /Fl lab3.asm 9. If you get any error on your code, take a look at lab3.lst (you can use notepad++). It shows the generated machine code side-by-side with your assembly language. Always pay attention to the first error as subsequent errors may be caused by the first one. Correct your error by editing lab3.asm and then go back to step #8 (you will only need to re-assemble lab3.asm). 10.Link the program by using TLINK. At the DOS prompt type: C:\>tlink /v lab3.obj utils.obj The “/v” switch tells the linker to generate full symbolic information needed for the debugger. Note: MASM32 equivalent command is: C:\>link16 lab3.obj utils.obj,,,,, 11. Run your program a couple of times using different test values for a,b & c to verify that it operates correctly (as described on the Requirements section). 12. If the program doesn’t operate correctly, debug it using the Turbo Debugger tool. At the DOS prompt type: C:\>td lab3.exe Note: For MASM32 use DEBUG. The invocation command is: C:\>debug lab3.exe
X86 Assembly Language Programming for the PC (EET-241 / ENGR-275)
Walter Lara
Lab Report
To complete this lab you should provide the instructor with the following files: lab3.asm lab3.lst lab3.exe The files should be archived on a zip file and send via e-mail. The zip file should be named as follows: lab3_.zip (e.g., lab3_WalterLara.zip).