?? calculate.asm
字號:
%include "asm_header.h" ; get the same maccro and define global calculatesegment .bss quardword resq 1 ; this is keep quard word for pushing float stacksegment .textcalculate:;This function is use for walk on tree by using postorder recursively and calculate the result;Get to parameters one is pointer of top of tree ;return result in float format;EAX : use for keeping node;EBX : use for keeping the data of eax than munis 30h for finding integer value of char;EDX : use for temporary for keeping eax child and push it to stack;Stack frame for one calling recursive function; |top ptr of tree |; |-----------------|; |Return address |; |-----------------|; | EBP |; |-----------------| ; |top ptr of tree | ESP;pseudocode; 1 reverse 4 byte for local variable which is child of node; 2 get the parameter eax node ; 3 if node in eax is null jump the finish; 4 push the left child of node in eax and string; 5 call inorder for left child; 6 get the node in eax; 7 put the right child ; 8 call inorder for right child; 9 if node in eax is null jump the finish; 10 else if it is operator put to it float stack; 11 else undertand it is +,-,* or / than call it's function; 11.1 apply operator to st0 and st1; 12 leave and ret enter 4,0 ;reverse 4 byte for local varaible which is child of node ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;INITILIZE the program get the program argument which is only top of tree ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov eax , first_param ; get the top pointer of tree ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;END INITILIZE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;start_calculate: compare_null_jmp_je_finish eax ; if eax (node) is null jmp the finish move_than_push_it edx , dword left_child ;if it is node push it's left child call calculate ; call calculate for left child mov eax , first_param ; get the first parameter from the stack add esp , 4 ; move esp 4 byte for clear the local variable compare_null_jmp_je_finish eax ; if eax (node) is null jmp the finish move_than_push_it edx , dword right_child ; if it is node push it's right child call calculate ; call calculate for right child mov eax , first_param ; get the first parameter from stack compare_null_jmp_je_finish eax ; if eax (node) is null jmp the finish switch_case: cmp byte[eax] , '0' ; compare it is operator or operand jge add_float_stack ; if it is operand jump the add_float_stack cmp byte[eax] , '+' ;compare it is + je float_add ;if it is + than jump float add cmp byte[eax] , '-' ;compare it is a - je float_minus ;if it is - than jump float minus cmp byte[eax] , '*' ; compare it is a * je float_mul ;if it is * jump float mul cmp byte[eax] , '/' ;compare it is a / je float_div ;if it is / jump the float_div add_float_stack: mov ebx , dword data ;copy the data to ebx sub ebx , 30h ;munis 30h from char to make it integer mov dword [quardword], ebx ;put it the variable which is reserve for quard word fild qword [quardword] ;push the quardword to float stack jmp finish ;jump the finish float_add: faddp st1 ;pop the sto and st1 than add it and push the result to stack jmp finish ; jump the finish float_minus: fsubp st1 ;pop the sto and st1 than munis it and push the result to stack jmp finish ; jump the finishfloat_mul: fmulp st1 ;pop the sto and st1 than multiply it and push the result to stack jmp finish ; jump the finish float_div: fdivp st1 ;pop the sto and st1 than divide it and push the result to stack jmp finish ; jump the finishfinish: leave ; clean the stack and set the ebp and esp ret ; return to system startup routines;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END OF CALCULATE FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -