The programme does not turn to the mass



  • Assembler's program seems to be working right, except for one. but...- She doesn't turn to the mass, like I'm sending something wrong.

    Code:

    .model small
    .stack 128d
    .data 
    matrixSize equ 3 ;  задача решается для квадратной матрицы
    elementSize equ 2 ; размер элемента массива
    matrix  dw  1,2,3,4,5,6,7,8,9;матрица
    

    .code
    main:
    mov ax, @data
    mov ds, ax
    mov bx, 0
    mov bp, 0
    mov cx, matrixSize
    Cycle1:
    mov si, cx
    mov cx, matrixSize
    mov dx, 0

    mov ax, matrix[bp] ; не обращается к матрице
    mov dx, ax
    Cycle2:
    mov ax, dx
    sub matrix[bx], ax
    add bx, elementSize
    loop Cycle2
    add bp, elementSize*(matrixSize+1)
    mov cx, si
    loop Cycle1
    mov AH, 4Ch
    int 21h
    end main

    The objective is to provide a square matrix, each element shall be reduced by the size of the diagonal element of the corresponding line.



  • I think that's right. I've slightly modified the program so that it can be compromised by fasm, settled in dosbox with a fdpro. The cells are correctly recorded in AX, the data are changing correctly.

    Programme (compiled in com):

    format binary
    use16
    org 100h
    

    jmp main

    matrixSize equ 3 ; задача решается для квадратной матрицы
    elementSize equ 2 ; размер элемента массива
    matrix dw 1,2,3,4,5,6,7,8,9;матрица

    main:
    mov bx, 0
    mov bp, 0
    mov cx, matrixSize
    Cycle1:
    mov si, cx
    mov cx, matrixSize
    mov dx, 0

    mov ax, [matrix+bp]
    mov dx, ax
    Cycle2:
        mov ax, dx
        sub [matrix+bx], ax
        add bx, elementSize
        loop Cycle2
    add bp, elementSize*(matrixSize+1)
    mov cx, si
    loop Cycle1
    
    mov AH, 4Ch
    int 21h
    

    Reference status of the matrix:
    Исходное состояние матрицы

    After the team mov ax, [matrix+bp] In AX, the correct value was considered (in this case 1):
    Состояние регистра AX

    The final condition of the matrix (FF FF and FE FF is respectively -1 and -2):
    Конечное состояние матрицы

    If manual operations are performed, the reference matrix

    1  2  3
    4 5 6
    7 8 9

    At the end, it's gonna work.

     0  1  2
    -1 0 1
    -2 -1 0

    That's what I see on the last crypt.

    Updating

    Still downloaded tasm, checked the original version of the program on it.

    The problem was in the register bp. As has been shown, the SS register is used as a segment register by indirect address through it:

    As with the BX, SI and DI registers, the BP register can also be used in
    as an index to the memory cell, but there are some
    different. Registers BX, SI and DI usually refer to memory
    concerning segmental register DS (or, if used in
    Schematic instructions of the DI register concerning the segment register
    ES) a BP register is addressed to the memory of the SS register
    (Segmental Registry)

    (sighs) http://www.codenet.ru/progr/asm/tasm/13.php )

    Exit - or clearly indicate the segment register (ds:matrix[bp]or use another index register, e.g. the same DI, it defaults the memory of the segmental register DS (except for type of structural transactions movscmps and others, ES is used.

    Well, the squeaky one:
    скриншот

    Well, the last thing is, why was the BP address in my program? It's simple: I compiled in COM (TINY model), so the main segment registers were equal to each other (cs=ds==ssss), so the code and data, and the glasses are in one segment.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2