Skip to content

Instantly share code, notes, and snippets.

@martinsbalodis
Created May 28, 2012 20:08
Show Gist options
  • Save martinsbalodis/2820984 to your computer and use it in GitHub Desktop.
Save martinsbalodis/2820984 to your computer and use it in GitHub Desktop.
MOB_MD_ASM
.text
.align 2
.global const1
const1:
aa_check:
ldrb r1, [r0] @ ielasa tekošo simbolu
cmp r1, #0 @ aizmet uz beigam, jo vārds beidzies. nav nederīgu simbolu
beq success
cmp r1, #'a @ simbols nav a. met uz nākošo pārbaudes punktu
bne b_check
@ // otra a simbola pārbaude
add r0, r0, #1
ldrb r1, [r0] @ ielasa tekošo simbolu
cmp r1, #'a @ a pārbaude
bne fail
add r0, r0, #1
b aa_check
b_check:
ldrb r1, [r0] @ ielasa tekošo simbolu
cmp r1, #0 @ aizmet uz beigam, jo vārds beidzies. nav nederīgu simbolu
beq success
cmp r1, #'b @ simbols nav b. rezultats nederigs
bne fail
add r0, r0, #1
b b_check
error:
mov r0, #2
b end
success:
mov r0, #1
b end
fail:
mov r0, #0
end:
bx lr
.size const1, .-const1
#include <stdio.h>
#include <stdlib.h>
int const1(char[]);
void check(char value[]) {
if(const1(value)) {
printf("yes\n");
}
else {
printf("no\n");
}
}
int main (int argc, char **argv)
{
// (aa)*b*
check(""); // yes
check("a"); // no
check("aa"); // yes
check("aaa"); // no
check("aab"); // yes
check("b"); // yes
check("bb"); // yes
check("bba"); // no
return 0;
}
# Sample Makefile
TARGET := const1
OBJ := $(TARGET)_main.o $(TARGET).o
ASFLAGS = -mcpu=xscale -alh=$*.lis -L
CFLAGS = -mcpu=xscale -O0 -Wall
LDFLAGS =
CC := arm-linux-gnueabi-gcc
AS := arm-linux-gnueabi-as
.PHONY: test all clean distclean
test: all
qemu-arm $(TARGET)
all: $(TARGET)
clean:
$(RM) $(TARGET) *.o
distclean: clean
$(RM) *.lis *~
allhfiles := $(wildcard *.h)
$(TARGET): $(OBJ)
$(CC) $(LDFLAGS) -o $@ $^
%.o: %.s
$(AS) -g $(ASFLAGS) -o $@ $<
%.o: %.c $(allhfiles)
$(CC) -g $(CFLAGS) -o $@ -c $<
%.s: %.c $(allhfiles)
$(CC) $(CFLAGS) -fomit-frame-pointer -o $@ -S $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment