1. vaja rešitve

@-------------------------------------
@              naloga 1
@-------------------------------------

          .text
S1:       .byte 15
S2:       .byte 10


          .align
          .global __start

@ nepredznaceni, pogojni skoki

__start:  adr   r4,S1
          adr   r5,S2
         
          ldrb  r1,[r4]      @S1->r1
          ldrb  r2,[r5]      @S2->r2
         
          cmp   r1, r2       @r1 > r2
          bhi   vecjas1      @ da
         
          sub   r2, r2, r1
          strb  r2, [r5]
          b __end
         
vecjas1:  sub   r1, r1, r2   @ odstejem
          strb  r1, [r4]
         
__end:    b __end  



@-------------------------------------
@ predznaceni, pogojni skoki

__start:  adr   r4,S1
          adr   r5,S2
         
          ldrsb  r1,[r4]      @S1->r1
          ldrsb  r2,[r5]      @S2->r2
         
          cmp   r1, r2       @r1 > r2
          bgt   vecjas1      @ da
         
          sub   r2, r2, r1
          strb  r2, [r5]
          b __end
         
vecjas1:  sub   r1, r1, r2   @ odstejem
          strb  r1, [r4]

@-------------------------------------
@ predznaceni, pogojni izvajanje ukazov

__start:  adr   r4,S1
          adr   r5,S2
         
          ldrsb  r1,[r4]      @S1->r1
          ldrsb  r2,[r5]      @S2->r2
         
          cmp   r1, r2       @r1 > r2
         
          suble   r2, r2, r1
          strleb  r2, [r5]
         
vecjas1:  subgt   r1, r1, r2   @ odstejem
          strgtb  r1, [r4]
           

@-------------------------------------
@nepredzn., pogojno izvajanje ukazov

@ nepredznaceni, pogojni izvajanje ukazov

__start:  adr   r4,S1
          adr   r5,S2
         
          ldrb  r1,[r4]      @S1->r1
          ldrb  r2,[r5]      @S2->r2
         
          cmp   r1, r2       @r1 > r2
         
          subls   r2, r2, r1
          strlsb  r2, [r5]
         
vecjas1:  subhi   r1, r1, r2   @ odstejem
          strhib  r1, [r4]


@-------------------------------------
@naloga 2
@-------------------------------------

@-------------------------------------
@nepredznac.
          .text
tabela:   .byte 23,54,2,76,53,57,5,1,0,11
 
        
          .align
          .global __start
__start:
          /*
    mov r1, #53
    mov r1, #60
    */
    mov r1, #2
          adr r0, tabela
        
zanka:    ldrb r2, [r0]
          add r0, r0, #1
          cmp r2, r1
          /*
    bne zanka
    bls zanka
    */
    bhs zanka

 

@-------------------------------------
@predznac.
          .text
tabela:   .byte byte 0,-5,2,-4,11,12,32,-10,-11,-22
 
        
          .align
          .global __start
__start:
          /*
    mov r1, $11
    mov r1, #30
    */
    mov r1, #-11
          adr r0, tabela
        
zanka:    ldrb r2, [r0]
          add r0, r0, #1
          cmp r2, r1
          /*
    bne zanka
    ble zanka
    */
    bge zanka
 
 

@-------------------------------------
@            naloga 3a
@-------------------------------------
 
  .text
tabela: .byte 1,100,255,24,88,31,56,192,155,224,48,0,128,99,147,177
rez: .space 1

  .align
  .global __start
__start:

  adr r0, tabela       @ kazalec
  adr r4, rez           
  mov r1, #16         @ stevec zanke
  mov r2, #0           @ stevec
  
zanka: ldrsb r3, [r0]  @predzn!
  cmp r3, #90         @ >90 ?
  addgt r2, r2, #1  @ stevec++
  

 

  add r0, r0, #1

  subs r1, r1, #1
  bne zanka
  
  strb r2, [r4] @ rez <- stevec(r2=2)
 

@-------------------------------------
@              naloga 3b
@-------------------------------------
 
  .text
tabela: .byte 1,100,255,24,88,31,56,192,155,224,48,0,128,99,147,177
rez: .space 1

  .align
  .global __start
__start:

  adr r0, tabela       @ kazalec
  adr r4, rez           
  mov r1, #16         @ stevec zanke
  mov r2, #0           @ stevec
  
zanka: ldrb r3, [r0]
  cmp r3, #100       @ >100 ?
  addhi r2, r2, #1   @ stevec++
  

 

  add r0, r0, #1

  subs r1, r1, #1
  bne zanka
  
    strb r2, [r4]   @ rez <- stevec(r2=7)



@-------------------------------------
@naloga 3c
@-------------------------------------
 
  .text
tabela: .byte 1,100,255,24,88,31,56,192,155,224,48,0,128,99,147,177
rez: .space 1

  .align
  .global __start
__start:
 

adr r0, tabela       @ kazalec
  adr r4, rez           
  mov r1, #16         @ stevec zanke
  mov r2, #0           @ stevec
  
zanka: ldrb r3, [r0]
  cmp r3, #48         @ <48 ?
  blo preskoci  
  cmp r3, #57         @ >57 ?
  bhi preskoci
  add r2, r2, #1      @ stevec++

 

preskoci: add r0, r0, #1
  subs r1, r1, #1
  bne zanka
  
    strb r2, [r4]  @ rez <- stevec(r2=2

@-------------------------------------
@              naloga 4
@-------------------------------------
 
  .text
niz:  .byte –10,0,30,11,-20,32,-22,76,54,12
rez: .space 1

  .align
  .global __start
__start:
  adr r0, niz
  mov r1, #10
  ldrb r2, [r0] @ v r2 bo najmanjši element
  add r0, r0, #1
 
zanka: ldrb r3, [r0]
  cmp r3, r2
  bhi preskoci
  strb r3, niz @ r3 < r2
  strb r2, [r0]
  mov r2, r3
preskoci: add r0, r0, #1
  subs r1, r1, #1
  bne zanka

@-------------------------------------
@nepredzn., pogojni skoki

          ldrb r1, s1
          ldrb r2, s2

          cmp r1, r2
          bhi vecjas1
          sub r2, r2, r1
          strb r2, s2
          b __end
vecjas1:  sub r1, r1, r2
          strb r1, s1


@-------------------------------------
@predzn., pogojni skoki

          ldrsb r1, s1
          ldrsb r2, s2

          cmp r1, r2
          bgt vecjas1
          sub r2, r2, r1
          strb r2, s2
          b __end
vecjas1:  sub r1, r1, r2
          strb r1, s1
*/

@-------------------------------------
@predzn., pogojno izvajanje ukazov

          ldrsb r1, s1
          ldrsb r2, s2

          cmp r1, r2
          suble r2, r2, r1
          strleb r2, s2
          subgt r1, r1, r2
          strgtb r1, s1
           

@-------------------------------------
@nepredzn., pogojno izvajanje ukazov

  ldrb r1, s1
  ldrb r2, s2

  cmp r1, r2
  subls r2, r2, r1
  strlsb r2, s2
  subhi r1, r1, r2
  strhib r1, s1

 

 

@-------------------------------------
@naloga 2
@-------------------------------------

@-------------------------------------
@nepredznac.
          .text
tabela:   .byte 23,54,2,76,53,57,5,1,0,11
 
        
          .align
          .global __start
__start:
          /*
    mov r1, #53
    mov r1, #60
    */
    mov r1, #2
          adr r0, tabela
        
zanka:    ldrb r2, [r0]
          add r0, r0, #1
          cmp r2, r1
          /*
    bne zanka
    bls zanka
    */
    bhs zanka

 

@-------------------------------------
@predznac.
          .text
tabela:   .byte byte 0,-5,2,-4,11,12,32,-10,-11,-22
 
        
          .align
          .global __start
__start:
          /*
    mov r1, $11
    mov r1, #30
    */
    mov r1, #-11
          adr r0, tabela
        
zanka:    ldrb r2, [r0]
          add r0, r0, #1
          cmp r2, r1
          /*
    bne zanka
    ble zanka
    */
    bge zanka
 
 

@-------------------------------------
 @naloga 3a
@-------------------------------------
 
  .text
tabela: .byte 1,100,255,24,88,31,56,192,155,224,48,0,128,99,147,177
rez: .space 1

  .align
  .global __start
__start:
  adr r0, tabela
  mov r1, #16
  mov r2, #0
 
zanka: ldrsb r3, [r0]
  add r0, r0, #1
  cmp r3, #100
  addgt r2, r2, #1
  subs r1, r1, #1
  bne zanka
 
  strb r2, rez
 

 

@-------------------------------------
 @naloga 3b
@-------------------------------------

  .text
tabela: .byte 1,100,255,24,88,31,56,192,155,224,48,0,128,99,147,177
rez: .space 1

  .align
  .global __start
__start:
  adr r0, tabela
  mov r1, #16
  mov r2, #0
 
zanka: ldrb r3, [r0]
  add r0, r0, #1
  cmp r3, #100
  addhi r2, r2, #1
  subs r1, r1, #1
  bne zanka
 
  strb r2, rez
 

 

@-------------------------------------
 @naloga 3c
@-------------------------------------
 
  .text
tabela: .byte 1,100,255,24,88,31,56,192,155,224,48,0,128,99,147,177
rez: .space 1

  .align
  .global __start
__start:
  adr r0, tabela
  mov r1, #16
  mov r2, #0
 
zanka: ldrb r3, [r0]
  cmp r3, #48
  blo preskoci
  cmp r3, #57
  bhi preskoci
  add r2, r2, #1
preskoci: add r0, r0, #1
  subs r1, r1, #1
  bne zanka
 
  strb r2, rez
 
 

@-------------------------------------
 @naloga 4
@-------------------------------------
 

  .text
niz:  .byte –10,0,30,11,-20,32,-22,76,54,12
rez: .space 1

  .align
  .global __start
__start:
  adr r0, niz
  mov r4,r0                        @ v r4 bo kazalec na prvi podatek tabele

  mov r1, #10
  ldrsb r2, [r0]                   @ v r2 bo trenutno najmanjsi element
  add r0, r0, #1
  
zanka: ldrsb r3, [r0]        @ r3 .. podatek iz tabele
  cmp r3, r2
  bge preskoci                  @ preskoči, če podatek iz tabele (r3) >= trenutno najm. element (r2)
  

  strb r3, [r4]                     @ ce r3 < r2, zamenjaj
  strb r2, [r0]
  mov r2, r3


preskoci: add r0, r0, #1     @ povečaj »kazalec«
  subs r1, r1, #1
  bne zanka                        @ r1-krat ponovi zanko
Zadnja sprememba: petek, 18. november 2016, 22:35