Google Answers Logo
View Question
 
Q: debug ( No Answer,   0 Comments )
Question  
Subject: debug
Category: Computers > Hardware
Asked by: kffru-ga
List Price: $8.50
Posted: 14 Apr 2005 22:14 PDT
Expires: 15 Apr 2005 00:52 PDT
Question ID: 509507
.MODEL SMALL     ;assembler directive
.STACK 200h      ;necessary for space when int 21h is called
.DATA            ;variables and constants
     first_num   DW 100d     ;begin at 100
     last_num    DW 999d     ;end at 999

     myname     DB 'this program is to find prime numbers from 100 to
999', 0Ah, 0Dh, 0Ah, 0Dh,'$'
     done       DB 'Done$'
     crlf       DB 0Ah, 0Dh, '$'
     cr         DB 0Dh, '$'

.CODE  ;assembler directive

;first, establish access to the data segment by setting DS, in the
following 2-stage process
     MOV AX,@DATA
     MOV DS,AX
;Print headers
     MOV DX, OFFSET myname
     MOV AH, 9h    ;code for print a string
     INT 21h

MOV AX, first_num                    ;The first number
JMP FoundPrime                       ;One is prime, print it

NewNum:                              ;Next Number
  INC   AX                           ;Advance number 
  MOV   BX, 1

BeginTest:                           ;Start test loop
  INC   BX                           ;Advance divisor
  CMP   AX, last_num                 ;Check if number = 999
  JMP   FINISH_PROGRAM               ;EXIT
  CMP   AX, BX                       ;Check if number = divisor
  JE    FoundPrime                   ;If so, it's prime, loop finished
  MOV   CX, AX                       ;Save the number
  XOR   DX, DX                       ;Zero high DWord of divisor
  DIV   BX                           ;Divide number by divisor
  XCHG  DX, CX                       ;Prep remainder for testing 
  MOV   AX, DX                       ;Put number back
  JCXZ  NewNum                       ;If no renainder it's not prime
  JMP   BeginTest                    ;Next in test loop

FoundPrime:                          ;Print the prime number
  MOV   BX, AX                       ;Store current number
  MOV   SI, 10                       ;Load divisor with 10
  XOR   CX, CX                       ;Zero digit count

NON_ZERO:                            ;Calculate digits
  XOR   DX, DX                       ;Zero high DWord of divisor
  DIV   SI                           ;Divide number by divisor
  PUSH  DX                           ;Put the digit on the stack
  INC   CX                           ;Add one more digit to count
  OR    AX, AX                       ;Check for end of loop
  JNE   NON_ZERO                     ;Next digit to print
  MOV   AX, BX                       ;Restore the current number

WRITE_DIGIT_LOOP:                    ;Print digits
  POP   DX                           ;Get digit in reverse order
  ADD   DL,"0"                       ;Add ascii 0 to the value
  MOV   SI, AX                       ;Store ascii value
  MOV   AH,2                         ;Function 2h
  INT   21h                          ;Print it
  MOV   AX, SI                       ;Restore the ascii value
  LOOP  WRITE_DIGIT_LOOP             ;Next digit to print
  MOV   DL, " "                      ;A space
  MOV   CX, AX                       ;Store the current number
  MOV   AH,2                         ;Function 2h
  INT   21h                          ;Print it
  MOV   AX, CX                       ;Restore the test number
  JMP   NewNum                       ;Go next number

FINISH_PROGRAM:
  END                                ;End address


this program is to find prime number from 100 to 999 and print them on the screen
i can't find waht is wrong with it

i need the answer before Arpil 20
thanks
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy