Low-level Brainfuck

 3r33845. 3r3-31. 3r33737. Building a Brainfuck translator in TurboAssembler. 3r33737. 3r33831.  3r33845. 3r33831.  3r33845. For example, in Pascal. 3r33831.  3r33845. 3r33831.  3r33845. Let's write a code for + 3r33831.  3r33845. 3r33831.  3r33845. Therefore, we only need the bf-commands + and . 3r3663. 3r33831.  3r33845. 3r33831.  3r33845. 3r3742. 3r33737. var
data_mem: array[110]of integer; //data array 3r33845. command_mem: string; //command array
i: integer; //index of command array
j: integer; //index of data array
begin
j: = 1; 3r33845. readln (command_mem); 3r33845. 3r33845. for i: = 1 to length (command_mem) do begin //in the cycle we need the process
if (command_mem= '+') then data_mem[j]: = data_mem[j]+1; 3r33845. if (command_mem= '.') then write (chr (data_mem[j])); 3r33845. end; 3r33845. end. 3r33845. 3r33838. 3r33831.  3r33845. bf-code [b] ++++++++++++++++++++++++++++++++. 3r3663. will issue [b] ! 3r3663. 3r33831.  3r33845. 3r33737. (the ascii-code of the symbol [b] !
is 33 ). 3r33737. 3r33831.  3r33845. 3r33831.  3r33845. ideone.com . 3r33831.  3r33845. 3r366.
3r33831.  3r33845. Next, replace for operator with goto operator and add the bf-commands - 3r33333. 3r3663. . 3r33831.  3r33845. 3r33831.  3r33845. At the end, we will output the data array [i] data_mem
3r33831.  3r33845. 3r33831.  3r33845. 3r3742. 3r33737. LABEL prev, next; 3r33845. var
data_mem: array[110]of integer; 3r33845. command_mem: string; 3r33845. i, j, k: integer; 3r33845. begin
j: = 1; 3r33845. i: = 1; 3r33845. readln (command_mem); 3r33845. prev:
if i> length (command_mem) then goto next; 3r33845. if (command_mem= '+') then data_mem[j]: = data_mem[j]+1; 3r33845. if (command_mem[i]= '-') then data_mem[j]: = data_mem[j]-one; 3r33845. if (command_mem[i]= '>') then j: = j + 1; 3r33845. if (command_mem[i]= ' <') then j:=j-1;
if (command_mem[i]='. ') then write (chr (data_mem[j]));
3rr3845. i: = i + 1; 3r34538.
For k: = 1 to 10 do begin
Write (data_mem[k]);
Write ('');
End; 3r33845. End.
3r33030.  3r33845. 3r3118. ideone.com
3r33831.  3r33845. 3r33831.  3r33845. Next, let's add 3r3662.[
and ]3r3663. 3r33831.  3r33845. 3r33831.  3r33845. Add another variable [i] i_stor for bracket []3r3663. loop 3r33831.  3r33845. 3r33831.  3r33845. If the current item passed the check for [b] [ than load i to i_stor (if current item greater than zero).
By processing of the closing bracket ]3r3663. (if [i] data_mem
not equal zero ) load the address of the opening bracket [ into i from i_stor
[code]
LABEL prev,next;
var
data_mem: array[110]of integer; 3r33845. command_mem: string; 3r33845. i, j, k: integer; 3r33845. i_stor: integer; 3r33845. begin
j: = 1; 3r33845. i: = 1; 3r33845. readln (command_mem); 3r33845. prev:
if i> length (command_mem) then goto next; 3r33845. if (command_mem= '+') then data_mem[j]: = data_mem[j]+1; 3r33845. if (command_mem[i]= '-') then data_mem[j]: = data_mem[j]-one; 3r33845. if (command_mem[i]= '>') then j: = j + 1; 3r33845. if (command_mem[i]= ' <') then j:=j-1;
If . end;
if (command_mem[i]= ']') then
begin
if data_mem[j]> 0 then
begin
i: = i_str;
end; i: = i + 1;
goto prev;
next:
for k: = 1 to 10 do begin
write (data_mem[k]); 3r34545. write ("); 3r34538. end.

 3r33845. bf-code [b] +++++[>+<-]3r3663. transfers the number [b] 5
to the neighboring cell ??? ??? ??? 0 3r33831.  3r33845. 3r33831.  3r33845. ideone.com 3r33831.  3r33845. 3r33831.  3r33845. The HelloWorld code looks like ideone.com 3r33831.  3r33845. 3r33831.  3r33845. 3r33737. 3r3662. Moving on to TASM
3r33737. 3r33831.  3r33845. 3r33831.  3r33845. To organize the loop prev: (on which the transition will be made) loop 3r33831.  3r33845. 3r33831.  3r33845. 3r3742. 3r33737. mov CX, 28h; count of the stages of the loop
prev: label
; do stuff
loop prev; go back to label prev
3r33838. 3r33831.  3r33845. Let's create the data array data_mem . 3r33831.  3r33845. 3r33831.  3r33845. Let's create the command array command_mem (for clarity) put there ? ? ? ? ? ? ? ? ? 1 3r33831.  3r33845. 3r33831.  3r33845. In the loop, compare the current symbol with the symbol + and, if the characters are equal, increase the value of the current cell by 1
 3r33845. 3r33831.  3r33845. 3r3742. 3r33737. text segment; bf1.asm
assume cs: text, ds: data, ss: stk
begin:
mov AX, data; set the data segment
mov DS, AX
mov DL, command_mem; load the 1st command in the DL
mov CX, 0Ah; 10 stages 3r33845. prev:
cmp DL, '+'; the cell contains +
jne next; no, go to the label next:
mov BL, 00h; load into the index of data_mem
inc data_mem[BX]; yes, we increase the value of
next: 3r33845. inc i;
go to the array of commands. mov BL, i
mov DL, command_mem[BX]3r33845. loop prev 3r34545. 3r33845. mov AX, 4c00h; terminate the program
int 21h
text ends
3r33845. data segment
command_mem DB '+', '+', '+', '$'
data_mem DB ??????????? '$' 3r3-33845. i DB 0; command_mem index
data ends 3r33845. 3r33845. stk segment stack
db 100h dup (0); reserve 256 cells
stk ends
end begin
3r33838. 3r33831.  3r33845. Assembling (translation) tasm.exe bf1.asm . 3r33831.  3r33845. 3r33831.  3r33845. Linking is done with the command tlink.exe bf1.obj . 3r33831.  3r33845. 3r33831.  3r33845. After executing the program in the TurboDebagger , you can see that starting from address 0130 there are commands +++ . 3r33831.  3r33845. 3r33831.  3r33845. Next is the data array data_mem the variable i 3r3663. became equal to 0Ah
 3r33845. 3r33831.  3r33845. 3r33347. 3r33831.  3r33845. 3r33831.  3r33845. Next, add bf-commands - 3r33333. . 3r3663. 3r33831.  3r33845. To output a single character use the function [b] 02h of the interrupt int 21h . 3r33831.  3r33845. It is necessary (before calling the interrupt) DL
 3r33845. 3r33831.  3r33845. 3r3742. 3r33737. mov AH, 2
mov DL, character_code
int 21h
3r33838. 3r33831.  3r33845. Let's write the program entirely
 3r33845. 3r33831.  3r33845. 3r3742. 3r33737. text segment; bf2.asm
assume cs: text, ds: data, ss: stk
begin:
mov AX, data; set the data segment
mov DS, AX
mov DL, command_mem
mov CX, 0Ah
prev:
cmp DL, '+'
jne next
mov BL, j
inc data_mem[BX]3r33845. next: 3r33845. cmp DL, '-'        3r33845. jne next1
mov BL, j
dec data_mem[BX]3r33845. next1:
cmp DL, '>'
jne next2
inc j 3r33845. next2:
cmp DL, ' <'
jne next3
dec j 3r34545. next3:
cmp DL, '.' 3r33845. jne next4
mov AH, 2
mov BL, j
mov DL, data_mem[BX]3r33845. int 21h
next4:
inc i 3r34545. mov BL, i
mov DL, command_mem[BX]3r33845. loop prev 3r34545. 3r33845. mov AX, 4c00h; terminate the program
int 21h
text ends
3r33845. data segment
command_mem DB '+', '>', '+', '+', '$'; 3r33845. data_mem DB ??????????? '$' 3r3-33845. i DB 0; command_mem index
j DB 0; data_mem index
data ends 3r33845. 3r33845. stk segment stack
db 100h dup (0); reserve 256 cells
stk ends
end begin
3r33838. 3r33831.  3r33845. Low-level Brainfuck  3r33845. 3r33831.  3r33845. if the current element of command-mem not + then jump to the label next: (otherwise, perform + )
 3r33845. if the current element of command-mem not - 3r3663. then jump to the label [b] next1: 3r33831.  3r33845. if the current element of command-mem not > then jump to the label next2: 3r33831.  3r33845. if the current element of command-mem not 3r37777. then jump to the label [b] next3: 3r33831.  3r33845. if the current element of command-mem not . 3r3663. then jump to the label [b] next4: 3r33831.  3r33845. After the label next4: increase the index of command_mem on the label. prev: 3r33831.  3r33845. 3r33831.  3r33845. Next, add 3r3662.[
and ]3r3663. 3r33831.  3r33845. Add the variable i_stor 3r33831.  3r33845. If the current item passed the check for [b] [ then check current data_mem element for zero, and, if the current item is equal zero, jump further (on the next label), otherwise load i to i_stor
[code]next4:
cmp DL, 5Bh
; the cell contains[
jne next5
; no, go to the label next5
mov BL, j
mov DL, data_mem[BX]3r33845. cmp DL, 00; yes, check current data_mem element for zero
jz next5; if zero, jump further
mov DL, i; otherwise load i to i_stor
mov i_stor, DL
next5:
3r33838. 3r33831.  3r33845. When processing of the closing bracket ] (if data_mem not equal zero ) load the address of the opening bracket [ into i from i_stor
[code]next5:
cmp DL, 5Dh
; the cell contains ]3r33845. jne next6; no, go to the label next6
mov BL, j
mov DL, data_arr[BX]3r33845. cmp DL, 00; yes, check current data_mem element for zero
jz next6; if zero, jump further
mov DL, i_stor; otherwise load i_stor to i
mov i, DL
next6:
3r33838. 3r33831.  3r33845. Check the bf-code ++++[>+<-]3r3663. 3r33831.  3r33845. 3r33831.  3r33845. 3r3742. 3r33737. text segment; bf3.asm
assume cs: text, ds: data, ss: stk
begin:
mov AX, data; set the data segment
mov DS, AX
mov DL, command_mem
mov CX, 50h
3r33845. prev:
cmp DL, '+'
jne next
mov BL, j
inc data_mem[BX]3r33845. next: 3r33845. cmp DL, '-'
jne next1
mov BL, j
dec data_mem[BX]3r33845. next1:
cmp DL, '>'
jne next2
inc j 3r33845. next2:
cmp DL, ' <'
jne next3
dec j 3r34545. next3:
cmp DL, '.' 3r33845. jne next4
mov AH, 2
mov BL, j
mov DL, data_mem[BX]3r33845. int 21h
next4:
cmp DL, '['
; the cell contains[
jne next5
; no, go to the label next5
mov BL, j
mov DL, data_mem[BX]3r33845. cmp DL, 00; yes, check current data_mem element for zero
jz next5; if zero, jump further
mov DL, i; otherwise load i to i_stor
mov i_stor, DL
next5:
cmp DL, ']'; the cell contains]
jne next6; no, go to the label next6
mov BL, j
mov DL, data_mem[BX]3r33845. cmp DL, 00; yes, check current data_mem element for zero
jz next6; if zero, jump further
mov DL, i_stor; otherwise load i_stor to i
mov i, DL
next6:
inc i 3r34545. mov BL, i
mov DL, command_mem[BX]3r33845. loop prev 3r34545. 3r33845. mov AX, 4c00h; terminate the program
int 21h
text ends
3r33845. data segment
command_mem DB '+', '+', '+', '+', '[','>','+','<','-',']',' $ '
data_mem DB ??????????? '$' 3r3-33845. i DB 0; command_mem index
j DB 0; data_mem index
i_stor DB 0
data ends 3r33845. 3r33845. stk segment stack
db 100h dup (0); reserve 256 cells
stk ends
end begin
3r33838. 3r33831.  3r33845. 3r33655. 3r33831.  3r33845. 3r33831.  3r33845. Add the function to enter the line [b] 3fh
interrupt 21h 3r33831.  3r33845. 3r33831.  3r33845. 3r3742. 3r33737. mov ah, 3fh; input function
mov cx, 100h;
mov dx, OFFSET command_mem
int 21h
3r33838. 3r33831.  3r33845. 3r33737. loop
ends when the current character /command becomes '$'
 3r33845. 3r33831.  3r33845. 3r3742. 3r33737. cmp DL, '$'
je exit_loop
3r33838. 3r33831.  3r33845. Change loop to jmp 3r33831.  3r33845. 3r33831.  3r33845. 3r3742. 3r33737. mov ah, 3fh; input function
mov cx, 100h;
mov dx, OFFSET command_mem
int 21h
mov DL, command_mem; load the 1st command in the DL
; mov CX, 100h
prev:
cmp DL, '$'; check the current command for '$'
je exit_loop; jump if the check is successfully passed
3r33838. 3r33831.  3r33845. Add the [i] JUMPS 3r33716. directive. 3r33831.  3r33845. 3r33737. The JUMPS directive enables automatic conditional jump extending in TASM. TASM converts out. For example: 3r33831.  3r33845. 3r33831.  3r33845. 3r3742. 3r33737. JE EQUAL_PLACE
becomes:
JNE @@ A
JMP EQUAL_PLACE
@@ A:
3r33838. 3r33831.  3r33845. 3r33737. 3r33831.  3r33845. After all
 3r33845. 3r33831.  3r33845. 3r3742. 3r33737. JUMPS; bf4.asm
text segment
assume cs: text, ds: data, ss: stk
begin:
mov AX, data
mov DS, AX
;;; 3r33845. mov ah, 3fh
mov cx, 100h
mov dx, OFFSET command_mem
int 21h
;;; 3r33845. mov DL, command_mem
; mov CX, 100h
prev:
cmp DL, '$'
je exit_loop
cmp DL, '+'
jne next
mov BL, j
inc data_mem[BX]3r33845. next: 3r33845. cmp DL, '-'
jne next1
mov BL, j
dec data_mem[BX]3r33845. next1:
cmp DL, '>'
jne next2
inc j 3r33845. next2:
cmp DL, ' <'
jne next3
dec j 3r34545. next3:
cmp DL, '.' 3r33845. jne next4
mov AH, 2
mov BL, j
mov DL, data_mem[BX]3r33845. int 21h
next4:
cmp DL, '['
jne next5
mov BL, j
mov DL, data_mem[BX]3r33845. cmp DL, 00
jz next5
mov DL, i
mov i_stor, DL
next5:
cmp DL, ']'
jne next6
mov BL, j
mov DL, data_mem[BX]3r33845. cmp DL, 00
jz next6
mov DL, i_stor
mov i, DL
next6:
inc i 3r34545. mov BL, i
mov DL, command_mem[BX]3r33845. jmp prev 3r33845. exit_loop:
3r33845. MOV AH, 2
MOV DL, 0Ah
INT 21h
mov AX, 4c00h
int 21h
text ends
3r33845. data segment
command_mem DB 256h DUP ('$')
data_mem DB ??????????? '$' 3r3-33845. i DB ? '$'
j db ? '$'
i_stor DB ? '$'
data ends 3r33845. 3r33845. stk segment para stack
db 100h dup (0)
stk ends
end begin
3r33838. 3r33831.  3r33845. 3r33833. github.com
3r33841. 3r33845. 3r33845. 3r33838. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d,! 1): e.attachEvent ("onload", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r33838. 3r33845. 3r33841. 3r33845. 3r33845. 3r33845. 3r33845.
+ 0 -

Add comment