Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;************************************************
  2. ;* Beginn der globalen Daten *
  3. ;************************************************
  4.                    AREA MyData, DATA, align = 2
  5.  
  6. isPrime FILL    1001,"x",1                          ;
  7. primeField FILL 500,0,2
  8.  
  9. ;***********************************************
  10. ;* Beginn des Programms *
  11. ;************************************************
  12.     AREA |.text|, CODE, READONLY, ALIGN = 3
  13. ; ----- S t a r t des Hauptprogramms -----
  14.                 EXPORT main
  15.                 EXTERN Init_TI_Board
  16. main            PROC
  17.                 bl    Init_TI_Board                 ;HW Initialisieren
  18. ;Laden von Konstanten in Register
  19.                 ldr r0,=isPrime                     ;Primzahlenfeld füllen
  20.                                                
  21. ;Zur Übersicht laden der Konstanten
  22.                 mov r1,#2                           ;r1= thisPrime
  23.                 mov r3,#32                          ;r3= maxValue(Wurzel 1000)
  24.                 add r3,r3,r0;                       ;Startpunkt+MaxValue
  25.                 mov r4,#1                           ;r4= counterFindNext
  26.                 mov r10,#"."                        ;Keine Primzahl
  27.                 mov r11,#1000                       ;höchste Zahl
  28. ;erste while schleife          
  29.                 cmp r1,r3                           ;ob thisPrime>maxValue(Wurzel 1000)
  30.                 ble starthochrechn                  ;gehe zu starthochrechn
  31.                 b forever                           ;beende Programm
  32.  
  33. starthochrechn  mov r5,r1                           ;bereite Sieb vor
  34.                 mul r5,r1  
  35.                 sub r5,r1
  36. ;zweite Schleife
  37.  
  38. hochrechnen     add r5,r1                           ;rechne um Primzahl hoch
  39.                 cmp r5,r11
  40.                 bpl findeprim
  41.                 mov r12,r0                          ;Primzahlenfeld fuellen
  42.                 add r12,r12,r5                      ;Bestimmung Vielfache
  43.                 strb r10,[r12]                      ;Vielfaches speichern
  44.                 b hochrechnen
  45.  
  46. ;dritte schleife
  47. findeprim       add r1,r1,#1                        ;Erhoehe die letzte Primzahl um 1
  48.                 add r4,r1,r0                        ;Primzahl+Offset
  49.                 ldrb r2,[r4]                        ;Lade Wert in r2
  50.                 cmp r4,r3                           ;Pruefung ob thisPrime<=maxValue
  51.                 bhs speichereum                     ;gehe zu speichereum
  52.                 cmp r2,#"x"                         ;Markieren von Primzahlen mit "x"
  53.                 beq starthochrechn                  ;gehe zu starthochrechn
  54.                 b findeprim                         ;gehe zu Schleifenanfang
  55.  
  56. ;Umspeichern der Primzahlen
  57. speichereum     add r0,#2                           ;Speichere:Start bei 2
  58.  
  59. primzahlenspeichern
  60.                 mov r9,#0                           ;index primefield mal 2
  61.                 mov r0,#0                           ;aktuelle zahl
  62. for                        
  63. if              cmp r0,#0                           ;
  64.                 beq end_if                          ;0 keine Primzahl
  65.                 cmp r0,#1                           ;
  66.                 beq end_if                          ;1 keine Primzahl
  67.                 ldr r1,=isPrime                     ;
  68.                 ldrb r1,[r1,r0]                     ;aktuelle Zahl aus Sieb laden
  69.                 cmp r1,#"x"                         ;Sieb der aktuellen zahl Vergleich mit "x"
  70.                 bne end_if                          ;markiert als "."(nichtprim)
  71. then            ldr r7,=primeField                  ;Primzahlenfeld in r7 Ladne
  72.                 strh r0,[r7,r9]                     ;aktuelle Zahl in Primefield speichern
  73.                 add r9,#2                           ;Primfeldindex erhöhen
  74. end_if          add r0,#1                           ;Aktuelle Zahl erhöhen
  75.                 cmp r0,#1000                        ;mit größter Zahl vergleichen(1000)
  76.                 bhs forever                        
  77.                 b for                              
  78.                
  79. end_for        
  80.  
  81.  
  82.                
  83. forever         ldr r0,=primeField       
  84.  
  85.                 b   forever                     ;
  86.                 ENDP
  87.                 END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement