How Do I Correct Errors in My TASM Code for Calculating Averages?

  • Thread starter Thread starter nuubik
  • Start date Start date
Click For Summary
SUMMARY

The forum discussion focuses on correcting errors in TASM (Turbo Assembler) code designed to calculate the average of negative elements in an array using index addressing. The user provided a code snippet that initializes a vector and attempts to compute the average but encounters issues. A key recommendation is to remove the unnecessary decrement of the CX register within the loop, as it affects the loop's execution. Additionally, the use of the debugger tdebug.exe is emphasized for stepping through the code and monitoring register values.

PREREQUISITES
  • Understanding of TASM (Turbo Assembler) syntax and structure
  • Familiarity with assembly language programming concepts
  • Knowledge of index addressing methods in assembly
  • Experience using debuggers, specifically tdebug.exe
NEXT STEPS
  • Learn how to effectively use tdebug.exe for debugging assembly code
  • Research common pitfalls in TASM programming and their solutions
  • Explore advanced index addressing techniques in assembly language
  • Study the implications of register manipulation in assembly loops
USEFUL FOR

Assembly language programmers, students learning TASM, and developers seeking to debug and optimize their assembly code for performance and accuracy.

nuubik
Messages
1
Reaction score
0

Homework Statement


I had to write program which finds all negative elements in columns and calculates their average values and i had to do this with index addressing method. My code below:
Code:
.model tiny
.code
.startup
           Org 100h
           Jmp Short Start
Vector     Dw  2, -7, -1, 16, -15
N          Equ 5

Start:

           Xor Bx, Bx
           Xor Dx, Dx
           Xor Si, Si
           Mov Cx, N
           Dec Cx
S:
           Mov Ax, Vector[Bx]   
           Add Bx, 2
           Cmp Ax, 0
           Jge _next
           Inc Si
           Add Dx, Ax
           
_next:     
           Dec Cx
           Loop S

AVG:
           Mov Ax, Dx
           Cwd
           Idiv Si

.exit 0
end
Could someone help me fixing my errors? I would be very thankful.
 
Physics news on Phys.org
Note that loop decrements cx. You don't need the dec cx instruction. Is there a debugger you can use to step through the code one instruction at a time so you can monitor the registers (these also let you view chunks of memory)?
 
The name of the debugger is tdebug.exe that comes with Turbo. It's pretty easy to use. If you're writing assembly code, it's pretty much essential to use a debugger.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 20 ·
Replies
20
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
7
Views
8K
  • · Replies 11 ·
Replies
11
Views
5K