Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ITT the ABC Programming Language

Name: Anonymous 2008-07-29 19:29

#include <stdio.h>

int main(int argc,char argv*[]){
  int i = 0;
  int BUFFA;

  while(argv[i]!='\0'){
    if(argv[i]='a')
      BUFFA++;
    else if(argv[i]='b')
      BUFFA--;
    else if(argv[i]='c')
      printf("%i\n",BUFFA);
    else printf("%s","Error.\n");
  }
}

Name: Anonymous 2011-01-02 22:40

All right I have a pseudo-working implementation, my former implementation was completely crippled, this implementation is only severely crippled by lacking error handling and the handling of the `;' character, it also assumes that the accumulator is unsigned, which it judging by the phone number example isn't.

;; abc.asm
;; @Author Gerald Jay Sussman
;; Assemble with $ nasm -f elf abc.asm
;; Link with     $ ld -s -o abc abc.o

%define PFBLEN    0xff

%macro    write    2
    pusha
    mov    ecx, %1
    mov    edx, %2
    mov    eax, 4
    mov    ebx, 1
    int    0x80
    popa
%endmacro

section    .bss
printf_buffer:    resw    PFBLEN
char_buffer:    resw    2
argc:        resw    2
randfd:        resw    2
randint:    resw    2

section    .data
error:    dw    "An error occured.", 0xa, 0
randf:    dw    "/dev/urandom", 0
newl:    dw    0xa
ascii:    db    0

section    .text
    global    _start

_start:
    pop    eax
    cmp    eax, 1
    jle    .error

    mov    [argc], eax

    mov    eax, 5
    mov    ebx, randf
    xor    ecx, ecx
    int    0x80

    mov    [randfd], eax

    pop    eax
    pop    ecx
    xor    edx, edx
    xor    ebx, ebx
.loop:
    mov    eax, [ecx + edx]

    cmp    al, 0x0
    je    .next

    cmp    al, 'a'
    je    .a
    cmp    al, 'b'
    je    .b
    cmp    al, 'c'
    je    .c
    cmp    al, 'd'
    je    .d
    cmp    al, 'r'
    je    .r
    cmp    al, 'n'
    je    .n
    cmp    al, '$'
    je    .cash
    cmp    al, 'l'
    je    .l
    cmp    al, 0x3b
    je    .dbg
.bottl:
    inc    edx
    jmp    .loop
.fin:
    mov    eax, 1
    mov    ebx, 0
    int    0x80
.next:
    write    newl, 1
    dec    dword [argc]
    cmp    dword [argc], 1
    jle    .fin
    pop    ecx
    xor    edx, edx
    jmp    .loop
.error:
    write    error, randf - error

    mov    eax, 1
    mov    ebx, 1
    int    0x80
.a:
    inc    ebx
    jmp    .bottl
.b:
    dec    ebx
    jmp    .bottl
.c:
    cmp    byte [ascii], 0
    je    .asint
.aschar:
    mov    dword [char_buffer], ebx
    write    char_buffer, 1
    jmp    .bottl
.asint:
    mov    eax, ebx
    call    print_eax_int
    jmp    .bottl
.d:
    neg    ebx
    jmp    .bottl
.r:
    pusha
    push    ebx
    mov    eax, 3
    mov    ebx, [randfd]
    mov    ecx, randint
    mov    edx, 8
    int    0x80

    pop    ebx
    inc    ebx
    xor    edx, edx
    mov    eax, [randint]
    idiv    ebx
    mov    [randint], edx
    popa
    mov    ebx, [randint]
    jmp    .bottl
.n:
    xor    ebx, ebx
    jmp    .bottl
.cash:
    xor    byte [ascii], 1
    jmp    .bottl
.l:
    xor    edx, edx
    jmp    .loop
.dbg:
    jmp    .error

print_eax_int:
    pusha
    lea    ecx, [printf_buffer + PFBLEN]
.loop:
    sub    ecx, 4

    xor    edx, edx
    mov    ebx, 10
    idiv    ebx
    add    edx, 0x30
   
    mov    [ecx], edx

    cmp    eax, 0
    jle    .ret

    jmp    .loop
.ret:
    mov    eax, 4
    mov    ebx, 1
    lea    edx, [printf_buffer + PFBLEN]
    sub    edx, ecx
    int    0x80
    popa
    ret

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List