Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;::::::::::::::::::::::::::::::::::::::::::::::::::::
- ;
- ; file: matrix.asm
- ;
- ; This program propmts for a matrix, and then
- ; transposes it.
- ;
- ; Input: Number of columns, number of rows, and then
- ; actual values that are inside the matrix.
- ;
- ; Output: Prints string without leading/duplicate
- ; spaces
- ;
- ; Author: Caiden Robinson
- ; Date: 4/26/11
- ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- %include "asm_io.inc"
- segment .data
- row_num_p DB "Please enter the desired number of rows(10 max): ", 0
- col_num_p DB "Please enter the desired number of columns(10 max): ", 0
- matrix_p DB "Please enter each element of the matrix one at a time. Each input will be incremented by row, then column.", 0
- m_elm_p DB " > ", 0
- segment .bss
- row_len resd 1
- col_len resd 1
- Trow_len resb 1
- Tcol_len resb 1
- matrix resd 100
- T_matrix resd 100
- matrix_end resd 1
- index resd 1
- segment .text
- global asm_main
- asm_main:
- enter 0,0 ; setup routine
- pusha
- begin:
- row_p:
- mov EAX, row_num_p
- call print_string
- call read_int
- cmp EAX, 10
- jg row_p
- mov [row_len], EAX
- col_p:
- mov EAX, col_num_p
- call print_string
- call read_int
- cmp EAX, 10
- jg col_p
- mov [col_len], EAX
- mov EAX, matrix_p
- call print_string
- call print_nl
- mov EAX, [row_len]
- imul EAX, [col_len]
- imul EAX, 4
- add EAX, matrix
- mov [matrix_end], EAX
- mov EAX, matrix
- mov [index], EAX
- call print_int
- mov EAX, matrix
- call print_nl
- call print_int
- mov EAX, [matrix_end]
- call print_nl
- call print_int
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;READS IN THE MATRIX
- rd_loop:
- mov EAX, m_elm_p
- call print_string
- call read_int
- call print_nl
- mov EBX, [index]
- mov [EBX], EAX
- add EBX, 4
- cmp EBX, [matrix_end]
- je end_loop
- mov [index], EBX
- jmp rd_loop
- end_loop:
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- push dword matrix
- push dword [matrix_end]
- push dword [row_len]
- call display_Matrix
- done2:
- popa
- mov eax, 0 ; return back to C
- leave
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;
- segment .bss
- mat resd 1
- mat_last resd 1
- rl resd 1
- r_a resd 1
- segment .text
- display_Matrix:
- ;dump_stack 1, 0, 4
- push EBP
- mov EBP, ESP
- Add EBP, 8
- mov EAX, [EBP]
- mov [rl], EAX
- Add EBP, 4
- mov EAX, [EBP]
- mov [mat_last], EAX
- Add EBP, 4
- mov EAX, [EBP]
- mov [mat], EAX
- mov EAX, [rl]
- call print_int
- call print_nl
- IMUL EAX, 4
- dump_regs 3
- call print_int
- call print_nl
- mov [rl], EAX
- mov EBX, 0
- sub dword [rl], 4
- col_switch:
- row_disp:
- ;dump_regs 1
- mov EAX, [mat + EBX]
- ;dump_regs 2
- call print_int
- cmp [rl], EBX
- je r_d_end
- add EBX, 4
- jmp row_disp
- r_d_end:
- call print_nl
- mov EAX, [mat_last]
- cmp EAX, [mat + EBX + 4]
- je c_s_end
- jmp col_switch
- c_s_end:
- pop EBP
- ;dump_stack 2, 0, 4
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement