Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Example Program shows Prime numbers

ajtr211ajtr211 Member Posts: 31
This program is ready for assembling and linking
All procedures have been included in the program
ajtr211

title Primes.asm
;Shows sieve of Eratosthenes
;prints out total number

max equ 16381
display equ 2h
print_m equ 9h
doscall equ 21h
.data
numbers BYTE max DUP (?)
mess1 BYTE 'CALCULATING...$'
mess2 BYTE ' $'
.CODE
main proc far
push ds
sub ax,ax
push ax
mov ax,@data
mov ds,ax
mov dx,offset mess1
mov ah,print_m
int Doscall

mov cx,0
mov bx,3
fill_0:
mov [numbers + bx],0
inc bx
inc bx
cmp bx,max
jle fill_0

mov bx,3
search:
mov al,[numbers + bx]
mov al,1
je go_next
call binidec
inc cx
mov si,bx
cross_out:
add si,bx
cmp si,max
jg go_next
mov [numbers +si],1
jmp cross_out
go_next:
inc bx
inc bx
cmp bx,max
jle search
mov bx,cx
call binidec

ret
main endp
binidec proc
push bx
push cx

mov dx,offset mess2
mov ah,print_m
int doscall

mov cx,10000d
call dec_div
mov cx,1000d
call dec_div
mov cx,100d
call dec_div
mov cx,10d
call dec_div
mov cx,1d
call dec_div

pop cx
pop bx

ret

dec_div proc
mov ax,bx
cwd ;ax into ax and dx
div cx
mov bx,dx
mov dl,al
add dl,30h
mov ah,2
int 21h

ret
dec_div endp
binidec endp

end main

output:last part of program starts at 00003 to 16381

15919 15921 15923 15925 15927 15929 15931 15933 15935 15937
15939 15941 15943 15945 15947 15949 15951 15953 15955 15957
15959 15961 15963 15965 15967 15969 15971 15973 15975 15977
15979 15981 15983 15985 15987 15989 15991 15993 15995 15997
15999 16001 16003 16005 16007 16009 16011 16013 16015 16017
16019 16021 16023 16025 16027 16029 16031 16033 16035 16037
16039 16041 16043 16045 16047 16049 16051 16053 16055 16057
16059 16061 16063 16065 16067 16069 16071 16073 16075 16077
16079 16081 16083 16085 16087 16089 16091 16093 16095 16097
16099 16101 16103 16105 16107 16109 16111 16113 16115 16117
16119 16121 16123 16125 16127 16129 16131 16133 16135 16137
16139 16141 16143 16145 16147 16149 16151 16153 16155 16157
16159 16161 16163 16165 16167 16169 16171 16173 16175 16177
16179 16181 16183 16185 16187 16189 16191 16193 16195 16197
16199 16201 16203 16205 16207 16209 16211 16213 16215 16217
16219 16221 16223 16225 16227 16229 16231 16233 16235 16237
16239 16241 16243 16245 16247 16249 16251 16253 16255 16257
16259 16261 16263 16265 16267 16269 16271 16273 16275 16277
16279 16281 16283 16285 16287 16289 16291 16293 16295 16297
16299 16301 16303 16305 16307 16309 16311 16313 16315 16317
16319 16321 16323 16325 16327 16329 16331 16333 16335 16337
16339 16341 16343 16345 16347 16349 16351 16353 16355 16357
16359 16361 16363 16365 16367 16369 16371 16373 16375 16377
16379 08189Press any key to continue . . .


Comments

  • emu8086emu8086 Member Posts: 125
    [b][red]This message was edited by emu8086 at 2002-10-21 12:22:0[/red][/b][hr]
    I converted your code to be emu8086 compatible,
    by the way, there is some kind of bug, the last printed
    number seems to be out of the order or something...
    Anyway it's a piece of code!

    [code]
    ; ------------------------ code starts here ------------------------

    #make_COM# ; comment out if not emu8086!

    ORG 100h

    ;Shows sieve of Eratosthenes
    ;prints out total number

    max equ 50
    display equ 2h
    print_m equ 9h
    doscall equ 21h

    JMP main

    numbers db max DUP (?)
    mess1 db 'CALCULATING...$'
    mess2 db ' $'

    main proc far
    push ds
    sub ax,ax
    push ax
    mov ax,cs
    mov ds,ax
    mov dx,offset mess1
    mov ah,print_m
    int Doscall

    mov cx,0
    mov bx,3
    fill_0:
    mov [numbers + bx],0
    inc bx
    inc bx
    cmp bx,max
    jle fill_0

    mov bx,3
    search:
    mov al,[numbers + bx]
    mov al,1
    je go_next
    call binidec
    inc cx
    mov si,bx
    cross_out:
    add si,bx
    cmp si,max
    jg go_next
    mov [numbers +si],1
    jmp cross_out
    go_next:
    inc bx
    inc bx
    cmp bx,max
    jle search
    mov bx,cx
    call binidec

    ret
    main endp
    binidec proc
    push bx
    push cx

    mov dx,offset mess2
    mov ah,print_m
    int doscall

    mov cx,10000
    call dec_div
    mov cx,1000
    call dec_div
    mov cx,100
    call dec_div
    mov cx,10
    call dec_div
    mov cx,1
    call dec_div

    pop cx
    pop bx

    ret
    binidec endp

    dec_div proc
    mov ax,bx
    cwd ;ax into ax and dx
    div cx
    mov bx,dx
    mov dl,al
    add dl,30h
    mov ah,2
    int 21h

    ret
    dec_div endp


    end main
    [/code]


  • DariusDarius Member Posts: 1,666
    : This program is ready for assembling and linking
    : All procedures have been included in the program
    : ajtr211
    :
    : title Primes.asm
    : ;Shows sieve of Eratosthenes
    : ;prints out total number
    :
    : max equ 16381
    : display equ 2h
    : print_m equ 9h
    : doscall equ 21h
    : .data
    : numbers BYTE max DUP (?)
    : mess1 BYTE 'CALCULATING...$'
    : mess2 BYTE ' $'
    : .CODE
    : main proc far
    : push ds
    : sub ax,ax
    : push ax
    : mov ax,@data
    : mov ds,ax
    : mov dx,offset mess1
    : mov ah,print_m
    : int Doscall
    :
    : mov cx,0
    : mov bx,3
    : fill_0:
    : mov [numbers + bx],0
    : inc bx
    : inc bx
    : cmp bx,max
    : jle fill_0
    :
    : mov bx,3
    : search:
    : mov al,[numbers + bx]
    : mov al,1
    : je go_next
    : call binidec
    : inc cx
    : mov si,bx
    : cross_out:
    : add si,bx
    : cmp si,max
    : jg go_next
    : mov [numbers +si],1
    : jmp cross_out
    : go_next:
    : inc bx
    : inc bx
    : cmp bx,max
    : jle search
    : mov bx,cx
    : call binidec
    :
    : ret
    : main endp
    : binidec proc
    : push bx
    : push cx
    :
    : mov dx,offset mess2
    : mov ah,print_m
    : int doscall
    :
    : mov cx,10000d
    : call dec_div
    : mov cx,1000d
    : call dec_div
    : mov cx,100d
    : call dec_div
    : mov cx,10d
    : call dec_div
    : mov cx,1d
    : call dec_div
    :
    : pop cx
    : pop bx
    :
    : ret
    :
    : dec_div proc
    : mov ax,bx
    : cwd ;ax into ax and dx
    : div cx
    : mov bx,dx
    : mov dl,al
    : add dl,30h
    : mov ah,2
    : int 21h
    :
    : ret
    : dec_div endp
    : binidec endp
    :
    : end main
    :
    : output:last part of program starts at 00003 to 16381
    :
    : 15919 15921 15923 15925 15927 15929 15931 15933 15935 15937
    : 15939 15941 15943 15945 15947 15949 15951 15953 15955 15957
    : 15959 15961 15963 15965 15967 15969 15971 15973 15975 15977
    : 15979 15981 15983 15985 15987 15989 15991 15993 15995 15997
    : 15999 16001 16003 16005 16007 16009 16011 16013 16015 16017
    : 16019 16021 16023 16025 16027 16029 16031 16033 16035 16037
    : 16039 16041 16043 16045 16047 16049 16051 16053 16055 16057
    : 16059 16061 16063 16065 16067 16069 16071 16073 16075 16077
    : 16079 16081 16083 16085 16087 16089 16091 16093 16095 16097
    : 16099 16101 16103 16105 16107 16109 16111 16113 16115 16117
    : 16119 16121 16123 16125 16127 16129 16131 16133 16135 16137
    : 16139 16141 16143 16145 16147 16149 16151 16153 16155 16157
    : 16159 16161 16163 16165 16167 16169 16171 16173 16175 16177
    : 16179 16181 16183 16185 16187 16189 16191 16193 16195 16197
    : 16199 16201 16203 16205 16207 16209 16211 16213 16215 16217
    : 16219 16221 16223 16225 16227 16229 16231 16233 16235 16237
    : 16239 16241 16243 16245 16247 16249 16251 16253 16255 16257
    : 16259 16261 16263 16265 16267 16269 16271 16273 16275 16277
    : 16279 16281 16283 16285 16287 16289 16291 16293 16295 16297
    : 16299 16301 16303 16305 16307 16309 16311 16313 16315 16317
    : 16319 16321 16323 16325 16327 16329 16331 16333 16335 16337
    : 16339 16341 16343 16345 16347 16349 16351 16353 16355 16357
    : 16359 16361 16363 16365 16367 16369 16371 16373 16375 16377
    : 16379 08189Press any key to continue . . .
    :
    :
    :

    You do realize this is (seemingly) just printing out all odd numbers. You did at least check the first few numbers right?

    Example: 16203/3=5401

    Also I have to ask why you are posting this in the first place.


    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

  • ajtr211ajtr211 Member Posts: 31
    : [b][red]This message was edited by emu8086 at 2002-10-21 12:22:0[/red][/b][hr]
    : I converted your code to be emu8086 compatible,
    : by the way, there is some kind of bug, the last printed
    : number seems to be out of the order or something...
    : Anyway it's a piece of code!
    :
    : [code]
    : ; ------------------------ code starts here ------------------------
    :
    : #make_COM# ; comment out if not emu8086!
    :
    : ORG 100h
    :
    : ;Shows sieve of Eratosthenes
    : ;prints out total number
    :
    : max equ 50
    : display equ 2h
    : print_m equ 9h
    : doscall equ 21h
    :
    : JMP main
    :
    : numbers db max DUP (?)
    : mess1 db 'CALCULATING...$'
    : mess2 db ' $'
    :
    : main proc far
    : push ds
    : sub ax,ax
    : push ax
    : mov ax,cs
    : mov ds,ax
    : mov dx,offset mess1
    : mov ah,print_m
    : int Doscall
    :
    : mov cx,0
    : mov bx,3
    : fill_0:
    : mov [numbers + bx],0
    : inc bx
    : inc bx
    : cmp bx,max
    : jle fill_0
    :
    : mov bx,3
    : search:
    : mov al,[numbers + bx]
    : mov al,1
    : je go_next
    : call binidec
    : inc cx
    : mov si,bx
    : cross_out:
    : add si,bx
    : cmp si,max
    : jg go_next
    : mov [numbers +si],1
    : jmp cross_out
    : go_next:
    : inc bx
    : inc bx
    : cmp bx,max
    : jle search
    : mov bx,cx
    : call binidec
    :
    : ret
    : main endp
    : binidec proc
    : push bx
    : push cx
    :
    : mov dx,offset mess2
    : mov ah,print_m
    : int doscall
    :
    : mov cx,10000
    : call dec_div
    : mov cx,1000
    : call dec_div
    : mov cx,100
    : call dec_div
    : mov cx,10
    : call dec_div
    : mov cx,1
    : call dec_div
    :
    : pop cx
    : pop bx
    :
    : ret
    : binidec endp
    :
    : dec_div proc
    : mov ax,bx
    : cwd ;ax into ax and dx
    : div cx
    : mov bx,dx
    : mov dl,al
    : add dl,30h
    : mov ah,2
    : int 21h
    :
    : ret
    : dec_div endp
    :
    :
    : end main
    : [/code]
    :
    : THANKS!
    ajtr211
    :

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _____ [ http://forcoder.org ] free ebooks and video tutorials about < MATLAB, Visual Basic .NET, Visual Basic, C++, Objective-C, PL/SQL, C, Python, R, C#, Java, Scratch, JavaScript, Perl, Swift, Ruby, Delphi, Assembly, Go, PHP Logo, Awk, Bash, Alice, Dart, Ada, VBScript, ABAP, Scala, COBOL, Apex, ML, Lua, Erlang, Hack, Kotlin, Scheme, LabVIEW, Julia, SAS, FoxPro, D, Fortran, Lisp, Clojure, F#, Crystal, Rust, Prolog, Transact-SQL /> ________

Sign In or Register to comment.