flat assembler
Message board for the users of flat assembler.
Index
> Programming Language Design > Plain English Programming Goto page Previous 1, 2, 3, 4, 5 |
Author |
|
Tomasz Grysztar 06 May 2015, 10:25
I find some of the discussions happening in this thread really interesting and I'm considering creating a new sub-forum for this kind of topics, so they would not become lost inside the "heap" - perhaps a forum dedicated to the design of programming languages and compilers (the design of fasm and my new engine could also be discussed there).
|
|||
06 May 2015, 10:25 |
|
fasmnewbie 06 May 2015, 12:36
Tomasz Grysztar wrote: I find some of the discussions happening in this thread really interesting and I'm considering creating a new sub-forum for this kind of topics, so they would not become lost inside the "heap" - perhaps a forum dedicated to the design of programming languages and compilers (the design of fasm and my new engine could also be discussed there). |
|||
06 May 2015, 12:36 |
|
Mike Gonta 23 Dec 2017, 21:02
The current Plain English compiler produces only x86 (32 bit) Windows executables. It uses calls to short assembly
language (machine code) subroutines as primitives. While not significant short comings, optimized x64 (64 bit) code would be a nice feature. Here I've coded one of the longer machine code primitives in Plain English and then hand translated that to C. I then cleaned up the gcc asm output and commented it with the original Plain English code line by line. Plain English: Code: To compare a string to another string given a length and another length (equal only): Privatize the length. If the length is not the other length; say no. If the length is 0; say yes. Put the string's first into a pointer. Put the other string's first into another pointer. Loop. Put the pointer's target into a byte. Put the other pointer's target into another byte. Uppercase the byte. Uppercase the other byte. If the byte is not the other byte; say no. Add 1 to the pointer. Add 1 to the other pointer. Subtract 1 from the length. If the length is 0; say yes. Repeat. Code: #define BYTE unsigned char #define WYRD short #define DWORD long #define QWORD unsigned long long #define NUMBER long long #define LENGTH NUMBER #define BOOL NUMBER #define POINTER NUMBER typedef struct{ BYTE a[16]; } STRING; #define privatize(type, pointer) type private_##pointer = *pointer #define private(pointer) &private_##pointer #define cmpEq(variable, anotherVariable) *variable == *anotherVariable? 1: 0 #define cmpLt(variable, anotherVariable) *variable < *anotherVariable? 1: 0 #define cmpGt(variable, anotherVariable) *variable > *anotherVariable? 1: 0 #define mov(variable, anotherVariable) *variable = *anotherVariable #define add(variable, anotherVariable) *variable += *anotherVariable #define sub(variable, anotherVariable) *variable -= *anotherVariable #define mov_IndirectBytePtr(pointer, anotherPointer, offset) \ *pointer = (BYTE *)(QWORD)(*(QWORD *)(anotherPointer + offset)) static NUMBER zero = 0; static NUMBER one = 1; static NUMBER little2DA = 97; static NUMBER little2DZ = 122; static NUMBER space2DKey = 32; // To uppercase a byte: static void UppercaseAByte ( BYTE *byte ){ if (cmpLt(byte, &little2DA)) return; if (cmpGt(byte, &little2DZ)) return; sub(byte, &space2DKey); } // To compare a string to another string given a length and another length (equal only): NUMBER CompareAStringToAnotherStringGivenALengthAndAnotherLength28EqualOnly29 ( STRING *string, STRING *anotherString, LENGTH *length, LENGTH *anotherLength ){ NUMBER result; BYTE *pointer, *anotherPointer; privatize(LENGTH, length); BYTE byte, anotherByte; while (1){ if (!(cmpEq(length, anotherLength))) {result = zero; goto exit;} mov_IndirectBytePtr(&pointer, string, 0); mov_IndirectBytePtr(&anotherPointer, anotherString, 0); while (1){ if (cmpEq(&private_length, &zero)) {result = one; goto exit;} mov(&byte, pointer); mov(&anotherByte, anotherPointer); UppercaseAByte(&byte); UppercaseAByte(&anotherByte); if (!(cmpEq(&byte, &anotherByte))) {result = zero; goto exit;} add(&pointer, &one); add(&anotherPointer, &one); sub(&private_length, &one); } } exit: return result; } Code: use64 CompareAStringToAnotherStringGivenALengthAndAnotherLength28EqualOnly29: mov r10, QWORD [r8] ; Privatize the length. xor eax, eax cmp r10, QWORD [r9] je .L13 .L5: rep ret ; If the length is not the other length; say no. align 16 .L13: test r10, r10 ; If the length is 0; say yes. mov rcx, QWORD [rcx] ; Put the string's first into a pointer. mov r11, QWORD [rdx] ; Put the other string's first into another pointer. je .L10 sub r11, rcx jmp .L8 align 16 .L14: ; Loop. add rcx, 1 ; Add 1 to the pointer. ; Add 1 to the other pointer. sub r10, 1 ; Subtract 1 from the length. je .L10 ; If the length is 0; say yes. .L8: movzx r8d, BYTE [rcx] ; Put the pointer's target into a byte. movzx edx, BYTE [rcx + r11] ; Put the other pointer's target into another byte. mov rax, r8 ; Uppercase the byte. sub r8, 97 lea r9d, [rax - 32] cmp r8, 25 movzx r8d, dl ; Uppercase the other byte. cmovbe eax, r9d sub r8, 97 lea r9d, [rdx - 32] cmp r8, 25 cmovbe edx, r9d cmp dl, al ; If the byte is not the other byte; say no. je .L14 ; Repeat. xor eax, eax ret align 16 .L10: mov eax, 1 ret |
|||
23 Dec 2017, 21:02 |
|
bazizmix 24 Dec 2017, 17:07
Quote: .L5: Who can explain the meaning of this instruction? |
|||
24 Dec 2017, 17:07 |
|
revolution 24 Dec 2017, 17:19
bazizmix wrote:
http://repzret.org/p/repzret/ Mike Gonta: When i read "say no" I don't get the feeling that it should also implicitly quit. Perhaps something like "say no; and finish". |
|||
24 Dec 2017, 17:19 |
|
Mike Gonta 24 Dec 2017, 17:59
revolution wrote: Mike Gonta: When i read "say no" I don't get the feeling that it should also implicitly quit. Perhaps something like "say no; and finish". the compiler may insert some cleanup code before the function exits, which is why I used goto exit instead of break. You will also notice that the entire function is enclosed in a while (1) {} (also part of the spec). This is so a Loop can start at the beginning of the function (actually after any compiler inserted init code), without actually requiring the Loop keyword. |
|||
24 Dec 2017, 17:59 |
|
porky11 12 Feb 2019, 13:04
I also had an idea for a similar language, but I don't think, forcing a programming langauge to sound too much like a natural language is a good idea.
I prefer taking the good ideas from natural languages and use them in programming languages without making it more complicated. I just found some document I wrote some months ago and just continued writing it a bit. Here is what I wrote down: https://gist.github.com/porky11/3a3113e8aac98070f80182275577ccfe I really would like to add some of these ideas into a programming language. But I'll open a new thread about my programming language anyway. |
|||
12 Feb 2019, 13:04 |
|
Goto page Previous 1, 2, 3, 4, 5 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.