Incinerator
Limp Gawd
- Joined
- Aug 31, 2005
- Messages
- 252
I'm using Borland Turbo Assembler (have to for this class) and the purpose of this program is to take in two ints, a limit and a divisor. Then, starting from one (lets call it count) to test whether count is divisible by 2 or the user defined divisor. If count is NOT divisible by 2 or the divisor, print that number out to the screen. This should continue until count reaches the user defined limit.
Here is the code that I have and I've tried tracing through it multiple times but I just cant seem to find the problem. If you have any ideas, let me know. thanks.
Here is the code that I have and I've tried tracing through it multiple times but I just cant seem to find the problem. If you have any ideas, let me know. thanks.
Code:
; Program 5
; program reads given number of integers from user
; the program should output the sum of all integers entered
.MODEL SMALL
.STACK 100H
.DATA
limit DW 0
divisor DW 0
;some DW 0
.CODE
GLOBAL ioputch:PROC, iocrlf:PROC, iowrdec:PROC, ioputs:PROC
GLOBAL iogets:PROC, ioscanch:PROC, ioscandec:PROC
MAIN PROC
MOV AX,@DATA
MOV ES,AX
MOV DS,AX
CALL iogets ; get input
CALL ioscandec ; reads first part of input
MOV divisor, AX ; moves first input into limit used for "limit"
CALL ioscandec ; reads second part of input
MOV limit, AX ; moves second input into divisor used for "divisor"
MOV CX, 1 ; initializes the counter to 1
mainloop:CMP CX, limit ; compares to "limit"
JE exit ; exit program if limit and CX are holding equal values
MOV AX, CX ; get ready for division (by "divisor")
CWD
IDIV divisor
CMP DX, 0 ; use modulo to see if even division or not
JE elseloop ; jump if divisible by divisor
MOV BX, 2
MOV AX, CX ; get ready for division by 2
CWD
IDIV BX
CMP DX, 0
JE elseloop
MOV AX, CX ; prepare for iowrdec
CALL iowrdec ; writes answer as integer
INC CX ; increment counter variable
CALL iocrlf ; cariage return, line feed
JMP mainloop
elseloop:INC CX ; increments variable
JMP mainloop ; start loop over
exit: MOV AH,04CH ; exit program
INT 21H
MAIN ENDP
END MAIN