2. vaja rešitve
@-------------------------------------
@ 1. naloga
@-------------------------------------
.data
niz: .byte –10,0,30,11,-20,32,-22,76,54,12
.text
.org 0x20
.align
.global __start
__start:
ldr r0, =niz
mov r4,r0 @ v r4 bo kazalec na prvi podatek tabele
mov r1, #9 @ 9 zato, ker bomo r0 že enkrat povečali in gledamo ostalih 9
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
__end: b __end
@-------------------------------------
@ 2. naloga
@-------------------------------------
.data
tabela: .byte 1,100,255,24,88,31,56,192,155,224,48,0,128,99,147,177
REZ: .byte 0
.text
.org 0x20
.align
.global __start
__start:
ldr r0, =tabela @ r0 naslov tabele
ldr r4, =REZ
mov r1,#16 @ stevec zanke
mov r2,#0 @ stevec elementov
zanka: ldrb r3,[r0]
@ a) tst r3, #0b10000 @ bit4 = 1 ? (9)
@ addne r2,r2,#1
@ b) and r3,r3,#0b11000001 @bit7,6=1 in bit0=1 ? (2)
@ cmp r3,#0b00000001
@ addeq r2,r2,#1
@ c) tst r3, #0b00111 @ bit0-2 = 0 ? (8)
@ addeq r2,r2,#1
@ d) and r3,r3,#0b01111 @bit7,6=1 in bit0=1 ? (3)
@ cmp r3,#0b00001000
@ addeq r2,r2,#1
dalje: add r0,r0,#1
subs r1,r1,#1
bne zanka
strb r2, [r4]
__end: b __end
@-------------------------------------
@ 3. naloga
@-------------------------------------
.data
S1: .byte 0b11111111
.text
.org 0x20
.align
.global __start
__start:
ldr r0, =S1 @ r0 naslov
ldrb r1,[r0]
and r2,r1,#0b00111111 @ a) ali bic r0, r0, #0b11000000
orr r3,r1,#0b110100 @ b)
eor r4,r1,#0b1001 @ c)
tst r1,#0b100000 @ d)
beq dalje
and r5,r1,#0b100100 @ e-9
cmp r5, #0b100000
beq dalje
dalje:
__end: b __end
@-------------------------------------
@ 4. naloga
@-------------------------------------
.data
niz: .asciz "OR: ponedeljek in cetrtek 12-14" @ testni niz
.text
.org 0x20
.align
.global __start
__start:
ldr r0, =niz
zanka: ldrb r3, [r0]
cmp r3, #0 @ konec niza ?
beq __end
cmp r3, #'a' @ manjši od ‘a’ ?
blo preskoci
cmp r3, #'z' @ večji od ‘z’ ?
bhi preskoci
sub r3, r3, #32 @ spremeni v veliko crko @ and r3, r3, #0b11011111 , eor...
strb r3,[r0] @ vpisi v niz preskoci:
preskoci: add r0, r0, #1
b zanka
__end: b __end
@ 1. naloga
@-------------------------------------
.data
niz: .byte –10,0,30,11,-20,32,-22,76,54,12
.text
.org 0x20
.align
.global __start
__start:
ldr r0, =niz
mov r4,r0 @ v r4 bo kazalec na prvi podatek tabele
mov r1, #9 @ 9 zato, ker bomo r0 že enkrat povečali in gledamo ostalih 9
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
__end: b __end
@-------------------------------------
@ 2. naloga
@-------------------------------------
.data
tabela: .byte 1,100,255,24,88,31,56,192,155,224,48,0,128,99,147,177
REZ: .byte 0
.text
.org 0x20
.align
.global __start
__start:
ldr r0, =tabela @ r0 naslov tabele
ldr r4, =REZ
mov r1,#16 @ stevec zanke
mov r2,#0 @ stevec elementov
zanka: ldrb r3,[r0]
@ a) tst r3, #0b10000 @ bit4 = 1 ? (9)
@ addne r2,r2,#1
@ b) and r3,r3,#0b11000001 @bit7,6=1 in bit0=1 ? (2)
@ cmp r3,#0b00000001
@ addeq r2,r2,#1
@ c) tst r3, #0b00111 @ bit0-2 = 0 ? (8)
@ addeq r2,r2,#1
@ d) and r3,r3,#0b01111 @bit7,6=1 in bit0=1 ? (3)
@ cmp r3,#0b00001000
@ addeq r2,r2,#1
dalje: add r0,r0,#1
subs r1,r1,#1
bne zanka
strb r2, [r4]
__end: b __end
@-------------------------------------
@ 3. naloga
@-------------------------------------
.data
S1: .byte 0b11111111
.text
.org 0x20
.align
.global __start
__start:
ldr r0, =S1 @ r0 naslov
ldrb r1,[r0]
and r2,r1,#0b00111111 @ a) ali bic r0, r0, #0b11000000
orr r3,r1,#0b110100 @ b)
eor r4,r1,#0b1001 @ c)
tst r1,#0b100000 @ d)
beq dalje
and r5,r1,#0b100100 @ e-9
cmp r5, #0b100000
beq dalje
dalje:
__end: b __end
@-------------------------------------
@ 4. naloga
@-------------------------------------
.data
niz: .asciz "OR: ponedeljek in cetrtek 12-14" @ testni niz
.text
.org 0x20
.align
.global __start
__start:
ldr r0, =niz
zanka: ldrb r3, [r0]
cmp r3, #0 @ konec niza ?
beq __end
cmp r3, #'a' @ manjši od ‘a’ ?
blo preskoci
cmp r3, #'z' @ večji od ‘z’ ?
bhi preskoci
sub r3, r3, #32 @ spremeni v veliko crko @ and r3, r3, #0b11011111 , eor...
strb r3,[r0] @ vpisi v niz preskoci:
preskoci: add r0, r0, #1
b zanka
__end: b __end
마지막 수정됨: 목요일, 19 10월 2023, 4:20 PM