Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

prime # assembly language program

Name: Anonymous 2007-08-06 0:52 ID:bXqn4xmn

I am learning assembly language and need some help in figureing out how to get this program to display only prime numbers from 2 to 19. please help /prog/

; prime.asm
; sample program to demonstrate procedures
; calulates and prints prime numbers from 1 to 20

include 'emu8086.inc'

org  100h ; set location counter to 100h

jmp CodeStart

DataStart:
   max dw 19
   space db " ", 0

CodeStart:
   mov bx, 2
  
   LoopStart:
      
       ; must be a prime
       mov ax, bx
       call print_num
      
       ; print a space
       mov si, offset space
       call print_string
      
       add bx, 1
       cmp bx, max

   jle LoopStart
  
   ret

   IsPrime PROC
       ; uses a loop to determine if number in bx is prime
       ; upon return if bx not prime dx will be 0, otherwise dx > 0

       ; we only have to test divisors from 2 to bx/2
      
       ; prepare to divide dx:ax / 2
       mov ax, bx        
       mov dx, 0
       mov cx, 2 
       div cx
      
       ; move result into si for loop
       mov si, ax
      
       ; assume the value is prime
       mov dx, 1
      
       ; start loop at 2
       mov cx, 2
      
       PrimeLoop:
      
           ; compare loop count(in cx) and max loop value (in si)
           cmp cx, si
          
           ; jump out of loop if count(cx) > si
           ja StopLabel
      
           ; divide test value (in bx) by loop count (in cx)
           mov ax, bx
           mov dx, 0           
           div cx
          
           ; check remainder (in dx), if zero then we found a divisor
           ; and the number cannot be prime
           cmp dx, 0
          
           ; if dx = 0 then we found a divisor and can stop looking
           je StopLabel
          
           ; increment count
           add cx, 1
      
       jmp PrimeLoop
      
       StopLabel:
      
       ret
   IsPrime ENDP
  
DEFINE_PRINT_STRING
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS

Name: Anonymous 2007-08-06 2:02 ID:1hq2l21u

Assemble it

Name: Anonymous 2007-08-06 3:09 ID:L4dVVD8B

write it in c, compile it, assemble it, run it

Name: Anonymous 2007-08-06 5:27 ID:ZFdkGaEy

If you are confused, apply labels to your registers.  Reading back your code will make a lot more sense. Also, write pseudocode first.

Not that I know my x86 ASM, but it looks like your code here will print the numbers 2-20, then exit the program.

Name: Anonymous 2007-08-06 9:14 ID:Heaven

; prime.asm
; sample program to demonstrate procedures
; calulates and prints prime numbers from 1 to 20

include 'emu8086.inc'

org  100h ; set location counter to 100h

jmp CodeStart

DataStart:
   primes db "2 3 5 7 11 13 17 19", 0

CodeStart:
   mov si, offset primes
   call print_string

   ret

Name: Anonymous 2007-08-06 15:32 ID:JcN7d5Nm


;CALCULATE AND PRINT PRIMES 1-20
FACTORS .DB 0
DIVDEND .DB 0
NUMBER  .DB 0
INTMAIN LDY #20
NEXT    TYA
        PHA ;save .A
        JSR ISPRIME ;sets Z if prime
        PLA ;restore .A
        BNE AINT
        ;[.A here will have a prime number]
        ;[Depending on architecture, insert print routine here]
        ;[Note, convert to ASCII (or unicore) first
        NOP
AINT    ;[if you want do something for non primes, put it here]
        DEY
        BPL NEXT
        RTS
ISPRIME ;number to be tested in A
        LDA #0
        STA FACTORS
        TAX
        DEX ;don't bother dividing by itself
        STA NUMBER ;save it because DIVTEST destroys .A
NEXT    LDA NUMBER
        JSR DIVTEST
        BNE ISNT
        INC FACTORS
ISNT    DEX
        CMP #1 ;don't bother dividing by 1
        BNE NEXT
        LDA FACTORS
        CMP #1
        RTS
DIVTEST ;divide A by X, set Z if even
        ;division by 0 results in infinite loop
        ;.A is destroyed, so save it if you need it
        STA DIVDEND
        TXA
DIVLOOP SBC DIVDEND
        BPL DIVLOOP
        LDA DIVDEND
        RTS

Name: Anonymous 2007-08-06 19:23 ID:jx2HC4LX

>>6
how do i converted to unicore

Name: Anonymous 2007-08-06 20:47 ID:WKAF6KUO

>>6
Oh wow, nostalgia

Name: Anonymous 2007-08-07 0:13 ID:d2MIerb0

Wait what? BNE? is this ARM?

Name: Anonymous 2007-08-07 0:36 ID:rwzeDXz5

bump if not equal

Name: Anonymous 2007-08-07 3:32 ID:nD2HJvqG

>>9
It's 6502.  The designers of the ARM instruction set were fans of the 6502 and borrowed a lot of syntax conventions from it.

Name: Anonymous 2007-08-07 3:53 ID:f004s9B3

>>11
Kudos.  I would have avr'd the fucker. Here's hoping his assignment is in x86.

Name: Anonymous 2007-08-07 6:43 ID:AqHcK/d6

>>11
Yep, that's because the project originally started at Acorn, in fact ARM originally stood for Acorn RISC Machine. Acorn were the creators of the BBC Micro range of machines which used the 6502 chip.

Name: Anonymous 2007-08-07 6:47 ID:YyKqZW5f

I was surprised to learn that the original designer of the ARM chip is a male to female transsexual

Name: Anonymous 2007-08-07 6:52 ID:Kx4gGFkQ

>>14
Can you believe it?

Name: Anonymous 2007-08-07 7:00 ID:AqHcK/d6

>>14
Computer science tends to have more than its fair share of M2F trannies, some other examples include Lynn Conway, Joanna Rutkowska and Jeri Ellsworth.

Name: Anonymous 2007-08-07 7:08 ID:Heaven

>>16
My theory is that most people who succeed in the Computer Science fields tend to be the girly, nerdy type who used to get picked on in school.

Name: Anonymous 2007-08-07 8:28 ID:Heaven

>>17
TRU.DAT

Name: Anonymous 2007-08-07 10:06 ID:Heaven

>>17
Nah, HR makes them do it to even the gender ratio. A quick slash with the scalpel, and suddenly you're an equal opportunity employer.

Name: Anonymous 2007-08-07 14:57 ID:hMAxa62i

It's the only way programmers can reproduce.

Name: Anonymous 2007-08-08 1:58 ID:hP53Kz/Z

Assembler eh?

i swore i would never use it again

Name: Anonymous 2007-08-08 4:39 ID:FDtUu/oZ

>>16

Um, I don't think Jeri was a male at any point...

Name: Anonymous 2007-08-08 4:45 ID:Heaven

>>22
Then you think incorrectly

Name: Anonymous 2007-08-08 16:56 ID:IJIshN4M

Name: Anonymous 2007-08-09 8:21 ID:fMeMAha2

disgusting

Name: ​​​​​​​​​​ 2010-10-21 23:35

Name: Anonymous 2011-02-03 4:21

Name: Anonymous 2011-02-04 13:08

Name: Anonymous 2011-02-04 19:45

Name: Anonymous 2011-03-31 12:07

I am the phantom autist

Name: Anonymous 2011-03-31 12:07

I am the phantom autist

Name: Anonymous 2011-03-31 12:07

I am the phantom autist

Name: Anonymous 2011-03-31 12:07

I am the phantom autist

Name: Anonymous 2011-05-30 19:14

>>24
proof?

Name: 脂肪燃焼 2011-05-31 2:53

催淫通販:http://www.yahookanpou.com/product/sfd.html
ペニス増大:http://www.yahookanpou.com/catalog/13.html
ベニクモ:http://www.yahookanpou.com/product/mycqf.html
花痴:http://www.yahookanpou.com/product/huachi.html
FLY D5:http://www.yahookanpou.com/product/cangyshui.html
D5 原液:http://www.yahookanpou.com/product/cys.html
男根増長素:http://www.yahookanpou.com/product/ngzzhang.html
Sex Slave:http://www.yahookanpou.com/product/sexslave.html
procomil spray:http://www.yahookanpou.com/product/ps.html
プロコミルスプレー :http://www.yahookanpou.com/product/ps.html
Xing霸:http://www.yahookanpou.com/product/xingbao.html
絶對高潮:http://www.yahookanpou.com/product/jueduigaochao.html
FAT BURNING:http://www.yahookanpou.com/product/fcjfrs.html
終極痩身カプセル:http://www.yahookanpou.com/product/zs.html
蟻王:http://www.yahookanpou.com/product/ywang.html
アリ王:http://www.yahookanpou.com/product/ywang.html
ANT KING:http://www.yahookanpou.com/product/ywang.html
勃動力三體牛鞭:http://www.yahookanpou.com/product/santiniu.html
西班牙昆虫粉:http://www.yahookanpou.com/product/xbykcf.html
漢方精力剤:http://www.yahookanpou.com/catalog/1.html
精力剤:http://www.yahookanpou.com/catalog/1.html
媚薬:http://www.yahookanpou.com/catalog/63.html
早漏防止:http://www.yahookanpou.com/catalog/14.html
滋養強壮:http://www.yahookanpou.com/catalog/15.html
漢方薬:http://www.yahookanpou.com/catalog/2.html
ED治療:http://www.yahookanpou.com/catalog/12.html
ED改善:http://www.yahookanpou.com/catalog/12.html
勃起促進:http://www.yahookanpou.com/catalog/16.html
女性用媚薬:http://www.yahookanpou.com/catalog/60.html
催淫:http://www.yahookanpou.com/catalog/63.html
催情:http://www.yahookanpou.com/catalog/63.html
性欲増強:http://www.yahookanpou.com/catalog/62.html
中絶薬:http://www.yahookanpou.com/catalog/25.html
避妊薬:http://www.yahookanpou.com/catalog/23.html
脂肪燃焼:http://www.yahookanpou.com/catalog/28.html
ダイエット:http://www.yahookanpou.com/catalog/4.html
新陳代謝:http://www.yahookanpou.com/catalog/30.html
肥滿:http://www.yahookanpou.com/catalog/29.html
漢方ダイエット:http://www.yahookanpou.com/catalog/4.html
ダイエット薬:http://www.yahookanpou.com/catalog/29.html
催淫カプセル:http://www.yahookanpou.com/product/jdgc.html
三便宝 販売:http://www.yahookanpou.com/product/sanbiSanbao.html
ビグレックス オイル:http://www.yahookanpou.com/product/vigrxoil.html
曲美 通販:http://www.yahookanpou.com/product/qm.html

Name: ­t 2012-02-21 17:21

a

Don't change these.
Name: Email:
Entire Thread Thread List