Low Level Brainfuck. Continuing

Movement I 3r33635.  3r3644. Movement II 3r33635.  3r3644. Part III 3r33635.  3r3644. 3r33635.  3r3644. We write brainfuck on TurboAssembler'e. 3r33635.  3r3644. 3r33635.  3r3644. Add the output of the array. data_arr ("Tape" Turing machines) on the screen. 3r33635.  3r3644. We write a program that displays the elements of an arbitrary array by means of the function 09h of the interrupt 21h. 3r33635.  3r3644.
3r33510. .model tiny; ascii-decoder.asm
jumps
.data
data_arr DB ?????????????? '$'; data 3r3644. 3r3644. .code 3r3644. ORG 100h
start:
; Prepare all the necessary r3r3644. mov AX, @data; set up the
data segment. mov DS, AX
;;;;;;;;;;;;;;;; 3r3644. MOV AH, 2; go to the new line
MOV DL, 0Ah
INT 21h
mov dx, offset data_arr; pointer to array of characters
mov ah, 09h; display line
int 21h
;;;;;;;;;; 3r3644. MOV AH, 2; go to the new line
MOV DL, 0Ah
INT 21h
3r3644. mov AX, 4c00h; completion of the program 3r3644. int 21h
end start
3r3628.
3r33635.  3r3644. On the screen we will see the ascii codes of the array. data_arr DB ????????????? '$' 3r3-33415. 3r33635.  3r3644. Low Level Brainfuck. Continuing 3r3638. 3r33635.  3r3644. In order to represent the elements of an array as numbers, we will use the operator. div . 3r33635.  3r3644. 3r33635.  3r3644. Team div NUMBER divides the register AX 3r3r1515. on 3r33414. NUMBER and puts the integer part of the division into AL 3r3415. , and the remainder of the division in [b] AH (3r33414. NUMBER 3r33415. Can be either a memory area or a general-purpose register) 3r3363635.  3r3644. 3r33635.  3r3644. We derive the 1st and 2nd elements of the array 3r3363535.  3r3644.
3r33510. .model tiny; ascii-decoder.asm
jumps
.data
data_arr DB 1?1?????????? '$'; data 3r3644. 3r3644. .code 3r3644. ORG 100h
start:
; Prepare all the necessary r3r3644. mov AX, @data; set up the
data segment. mov DS, AX
;;;;;;;;;;;;;;;; 3r3644. MOV AH, 2; go to the new line
MOV DL, 0Ah
INT 21h
; mov dx, offset data_arr; pointer to array of characters
; mov ah, 09h; display line
; int 21h
3r3644. ;; print the first number
sub AH, AH; reset the AH
mov AL, data_arr; divisible 3r3644. mov BL, 10; divider 3r3644. div BL; now in AL = tens, in AH = units
mov BX, AX
add BX, 3030h
mov AH, 2; interrupt symbol output function 21h
mov DL, BL; we derive the high order
int 21h
mov DL, BH; we derive the low order
int 21h
display the second number
sub AH, AH; reset the AH
mov AL, data_arr + 1; divisible 3r3644. mov BL, 10; divider 3r3644. div BL; now in AL = tens, in AH = units
mov BX, AX
add BX, 3030h
mov AH, 2; interrupt symbol output function 21h
mov DL, BL; we derive the high order
int 21h
mov DL, BH; we derive the low order
int 21h
;;;;;;;;;; 3r3644. MOV AH, 2; go to the new line
MOV DL, 0Ah
INT 21h
3r3644. mov AX, 4c00h; completion of the program 3r3644. int 21h
end start
3r3628.
3r33635.  3r3644. 3r33635.  3r3644. In order to display all the elements of the array, we will use the command loop . 3r33635.  3r3644. Put in the register CX 3r3r1515. the number of ticks equal to the number of elements in the array and at each tick we will add one to the index of the array 3r33414. i 3r3r1515. . 3r33635.  3r3644.
3r33510. .model tiny; ascii-decoder1.asm
jumps
.data
data_arr DB ?????1?1?1??2? '$'; data 3r3644. i DB ? '$'
3r3644. .code 3r3644. ORG 100h
start:
; Prepare all the necessary r3r3644. mov AX, @data; set up the
data segment. mov DS, AX
;;;;;;;;;;;;;;;; 3r3644. MOV AH, 2; go to the new line
MOV DL, 0Ah
INT 21h
; mov dx, offset data_arr; pointer to array of characters
; mov ah, 09h; display line
; int 21h
3r3644. mov CX, 0Ah
_prev:
;; we derive the number
; mov BL, i
sub AH, AH; reset the AH
mov AL, data_arr[BX]; divisible 3r3644. mov BL, 10; divider 3r3644. div BL; now in AL = tens, in AH = units
mov BX, AX
add BX, 3030h
mov AH, 2; interrupt symbol output function 21h
mov DL, BL; we derive the high order
int 21h
mov DL, BH; we derive the low order
int 21h
; print the empty character
sub DL, DL
int 21h
;;; 3r3644. sub BX, BX
inc i; increase the counter
mov BL, i
loop _prev
;;;;;;;;;; 3r3644. MOV AH, 2; go to the new line
MOV DL, 0Ah
INT 21h
3r3644. mov AX, 4c00h; completion of the program 3r3644. int 21h
end start
3r3628.
3r33635.  3r3644. Next, add a loop that displays the elements of the array as numbers in the main program. 3r33635.  3r3644.
3r33510. .model tiny
jumps
.data
str_arr DB 256h DUP ('$')
data_arr DB ??????????? '$'
i DB ? '$'
j db ? '$'
i_stor DB ? '$'
3r3644. .code 3r3644. ORG 100h
start:
3r3644. mov AX, @data
mov DS, AX
;;; 3r3644. mov ah, 3fh
mov cx, 100h
mov dx, OFFSET str_arr
int 21h
;;; 3r3644. mov DL, str_arr
prev:
cmp DL 24h
je exit_loop
3r3644. cmp DL, 2Bh
jne next
mov BL, j
inc data_arr[BX]3r3644. next:
cmp DL, 2Dh
jne next1
mov BL, j
dec data_arr[BX]3r3644. next1:
cmp DL, 3Eh
jne next2
inc j 3r3644. next2:
cmp DL, 3Ch
jne next3
dec j 3r3644. next3:
cmp DL, 2Eh
jne next4
mov AH, 2
mov BL, j
mov DL, data_arr[BX]3r3644. int 21h
next4:
cmp DL, 5Bh
jne next5
; mov BL, j
; mov DL, data_arr[BX]3r3644. ; cmp DL, 00
; jz next5
mov DL, i
mov i_stor, Dl
next5:
cmp DL, 5Dh
jne next6
mov BL, j
mov DL, data_arr[BX]3r3644. cmp DL, 00
jz next6
mov DL, i_stor
mov i, DL
next6:
inc i
mov BL, i
mov DL, str_arr[BX]3r3644. ; loop prev 3r3644. jmp prev
exit_loop:
;;;;;;;;;;;;;;;; 3r3644. MOV AH, 2; new line 3r3644. MOV DL, 0Ah; new line 3r3644. INT 21h; new line 3r3644. 3r3644. ; output data_arr
mov CX, 0Ah; 10 cycles of 3r3644. sub AL, AL; reset AL
mov i, AL; reset the counter
sub BX, BX; reset the BX
_prev:
; incorrect 1st element
sub AH, AH; reset the AH
mov AL, data_arr[BX]; divisible 3r3644. ; mov AL, data_arr + 1
mov BL, 10; divider 3r3644. div BL; quotient AL = tens and AH = units
mov BX, AX
add BX, 3030h
mov AH, 2; output function 2 interrupt 21h
mov DL, BL; print dozens
int 21h
mov DL, BH; we derive the units
int 21h
; print a space (empty character) 3r3r464. sub DL, DL
int 21h
;;; 3r3644. sub BX, BX
inc i; increase the array index
mov BL, i
loop _prev
;;;;;;;;;; 3r3644. MOV AH, 2; new line 3r3644. MOV DL, 0Ah; new line 3r3644. INT 21h; new line 3r3644. 3r3644. mov AX, 4c00h; completion of the program 3r3644. int 21h
end start
3r3628.
3r33635.  3r3644. Now HelloWorld looks like this
 3r3644. 3r33333. 3r33635.  3r3644. Since we do not handle numbers larger than [b] 99
, the number 100 is displayed incorrectly, the remaining numbers are displayed correctly. 3r33635.  3r3644. 3r33635.  3r3644. 3r33357. Nested brackets
3r33635.  3r3644. To handle the nested brackets, we will place the opening brackets in the stack, and the closing brackets will be removed from the stack. 3r33635.  3r3644. 3r33635.  3r3644. Let's write a simple program for working with a stack in Pascal. 3r33635.  3r3644.
3r33510. var
a: array[110]of integer; 3r3644. size: integer; 3r3644. 3r3644. procedure push (c: integer); 3r3644. begin
size: = size + 1; 3r3644. a[size]= c; 3r3644. end; 3r3644. 3r3644. procedure pop; 3r3644. begin
size: = size - 1; 3r3644. end; 3r3644. begin
size: = 0; 3r3644. Push (1); 3r3644. writeln (a[size]); 3r3644. Push (2); 3r3644. writeln (a[size]); 3r3644. Push (3); 3r3644. writeln (a[size]); 3r3644. Pop (); 3r3644. writeln (a[size]); 3r3644. Pop (); 3r3644. writeln (a[size]); 3r3644. end. 3r3644. 3r3628.
3r33635.  3r3644. Took 3r30000. hence r3r3638. 3r33635.  3r3644. You can check 3r3404. here is 3r3638. or here 3r33635.  3r3644. 3r33635.  3r3644. Change the procedure push so that when r3r3414. size
equal to zero we got a reference to the first element. 3r33635.  3r3644.
3r33510. procedure push (c: integer); 3r3644. begin
a[size+1]= c; 3r3644. size: = size + 1; 3r3644. end; 3r3644. 3r3628.
3r33635.  3r3644. Add a "stack" to the main program. 3r33635.  3r3644.
3r33510. Program bf5_stack; 3r3644. 3r3644. LABEL prev, next; 3r3644. var
a: array[110]of integer; 3r3644. size: integer; 3r3644. data_arr: array[110]of integer; //dataset
str_arr: string; //team 3r3644. i, j, k: integer; //indices of the string and array
i_stor: integer; 3r3644. 3r3644. //Stack
procedure push (c: integer); 3r3644. begin
a[size+1]= c; 3r3644. size: = size + 1; 3r3644. end; 3r3644. 3r3644. procedure pop; 3r3644. begin
size: = size - 1; 3r3644. end; 3r3644. {------------------------------------------------- -} 3r3644. begin
j: = 1; //The numbering of the elements in the array starts from
i: = 1; 3r3644. size: = 0; {Initially, the stack is empty}
//readln (str_arr); //read the string
//str_arr: = '+++[>+++[>+<-]<-]'; //3 * 3 = 9
str_arr: = '+++[> +++[>+++[>+<-]<-]<-]'; //3 ^ 3 = 27; 3r3644. 3r3644. prev:
if i> length (str_arr) then goto next; 3r3644. if (str_arr[i]= '+') then data_arr[j]: = data_arr[j]+1; 3r3644. if (str_arr[i]= '-') then data_arr[j]: = data_arr[j]-one; 3r3644. if (str_arr[i]= '>') then j: = j + 1; 3r3644. if (str_arr[i]= ' <') then j:=j-1;
if (str_arr[i]='. ') then write (chr (data_arr[j])); 3r2642644. //brackets
if (str_arr w2w2642644. //brackets
if (str_arr w2w2642644. //brackets
if (str_arr w2w2642644. //brackets
if (str_arr w2w2642644. //brackets
if (str_arr w2w2642644. //brackets 3r3r4644. if) ) then
begin
Pop ();
if (data_arr w2w2w33.> 0) then
begin
i = 3 w3w3w2w234.
: = i + 1; 3r3644. goto prev;
next: 3r3r644. for k: = 1 to 10 do begin
write (data_arr[k]); 3rr3644. write ('');
end;

3r3-33635.  3r3644. ideone.com 3r33635.  3r3644. If we meet the bracket, then we simply put its address in the stack, when we meet the closing bracket, then we extract its address from the stack, and if the value in the current cell is greater than zero, then we return to the opening bracket. 3r33635.  3r3644. An example of using the normal /“standard” stack is shown in program 3r30101. bf51_stack.pas
3r33635.  3r3644. 3r33635.  3r3644. “Add” the stack to the main assembler program 3r33635.  3r3644.
3r33510. .model tiny; bf7_stack_decoder.asm
jumps
.data
str_arr DB 256h DUP ('$'); 256 character buffer
data_arr DB ??????????? '$'; data 3r3644. i DB ? '$'; index of the element of the command array
j DB ? '$'; the index of the element of the data array
i_stor DB ? '$'
3r3644. .code 3r3644. ORG 100h
start:
; Prepare all the necessary r3r3644. mov AX, @ data; set up the
data segment. mov DS, AX
;;; 3r3644. mov ah, 3fh; input function 3r3644. mov cx, 100h; 256 characters 3r3644. mov dx, OFFSET str_arr
int 21h
;;; 3r3644. mov DL, str_arr; load the 1st command in the DL
; mov CX, 100h; 256 cycles of 3r3644. prev:
cmp DL, 24h; the symbol '$'
je exit_loop
cmp DL, 2Bh; the cell contains +
jne next; No, go to the label next
mov BL, j; load the
data index into the BL. inc data_arr[BX]; yes, we increase the value in the cell by 1
next:
cmp DL, 2Dh; cell contains -
jne next1; No, go to the label next1
mov BL, j
dec data_arr[BX]; BX, but not Bl
next1:
cmp DL, 3Eh; the cell contains>
jne next2; No, go to the label next2
inc j; Yes, go to the next element of the data_arr array
next2:
cmp DL, 3Ch; the cell contains 3r33551. jne next3; No, go to the label next3
dec j; Yes, go to the previous element of the data_arr array
next3:
cmp DL, 2Eh; cell contains. 3r3644. jne next4; No, go to the label next4
mov AH, 2; Yes, we display the contents of the cell
mov BL, j
mov DL, data_arr[BX]3r3644. int 21h
next4:
cmp DL, 5Bh; cell contains[
jne next5
; нет, переходим на метку next5
;sub DX,DX
mov AL, i
; иначе загружаем
push AX
next5:
cmp DL, 5Dh
; ячейка содержит ]3r3644. jne next6; No, go to the label next6
sub AX, AX
pop AX
mov BL, j
mov DL, data_arr[BX]3r3644. cmp DL, 00; Yes, we check the current data_arr element for zero
jz next6; if zero, jump further 3r3644. mov i, AL; in i_stor, the value of the variable i is
mov BL, i
mov DL, str_arr[BX]3r3644. jmp prev
next6:
inc i; go to the next team 3r3644. mov BL, i
mov DL, str_arr[BX]3r3644. jmp prev
exit_loop:
3r3644. ; Output ascii-character numbers
3r3644. MOV AH, 2; new line 3r3644. MOV DL, 0Ah; new line 3r3644. INT 21h; new line 3r3644. 3r3644. ; output data_arr
mov CX, 0Ah; 10 cycles of 3r3644. sub AL, AL; reset AL
mov i, AL; reset the counter
sub BX, BX; reset the BX
_prev:
; incorrect 1st element
sub AH, AH; reset the AH
mov AL, data_arr[BX]; divisible 3r3644. ; mov AL, data_arr + 1
mov BL, 10; divider 3r3644. div BL; quotient AL = tens and AH = units
mov BX, AX
add BX, 3030h
mov AH, 2; output function 2 interrupt 21h
mov DL, BL; print dozens
int 21h
mov DL, BH; we derive the units
int 21h
; print a space (empty character) 3r3r464. sub DL, DL
int 21h
;;; 3r3644. sub BX, BX
inc i; increase the array index
mov BL, i
loop _prev
;;;;;;;;;; 3r3644. MOV AH, 2; new line 3r3644. MOV DL, 0Ah; new line 3r3644. INT 21h; new line 3r3644. ;;;;;;;;;;;;;;; 3r3644. mov AX, 4c00h; completion of the program 3r3644. int 21h
END start
3r3628.
3r33635.  3r3644. 3r33232. 3r33635.  3r3644. 3r33635.  3r3644. 3r3637. Reference
on github. 3r3645. 3r3644. 3r3644.
3r3644. 3r3645.
+ 0 -

Add comment