Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize simple Mathematical Operation in Assembly language

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to realize simple mathematical operations in assembly language". In daily operation, I believe that many people have doubts about how to realize simple mathematical operations in assembly language. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to realize simple mathematical operations in assembly language". Next, please follow the editor to study!

5. Calculate the design requirements of Seven 1 × 3 × 3 × 4 × 5 + + N (Numb1) 5.1:

A program is designed to realize the algorithm of mathematical formula Snow1, 2 × 3, 3 × 4, 4 × 5 + N (Numb1). The value N is inputted by the keyboard, and the calculation result is output at the display terminal. Design requirements: the calculation result does not exceed the storage capacity of the 16-bit register, if there is an overflow prompt error.

5.2 Design ideas:

Input N value and then give N to BH as the number of cycles, through the loop to achieve multiplication and accumulation calculation, the result is hexadecimal, by dividing by 10 to get decimal, stored in the stack and then output in turn.

List of programs: DATA SEGMENT pkey DB 0dhjol 0ah, "pleas input N end by';': $" over DB 0AHJ 0DH, "overflow!", 0dhler0 h result DB 0dhlagle 0ah is:','$' DAT1 DB 8 DUP (0) DATA ENDSSTACK SEGMENT SSTACK DB 100 DUP (0) STACK ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACK STATE: MOV AX,DATA MOV DS,AX LEA SI,DAT1 Open up buffer LEA DX,pkey MOV AH,9 INT 21H; DOS function call, output string LLP:MOV AH,1 INT 21H; DOS function call, input N value SUB AL,2FH INC DX; DX count MOV [SI], AL; store the input data in SI buffer INC SI CMP AL,0CH Input is the end of the seal number, enter JNZ LLP SUB SI,2 CMP DX,02H; DX is not 2 means the input is a two-digit JNZ LLLP LLP1:MOV CX,1 MOV BL,2; assign initial values JMP LPLLLP: MOV DI,SI SUB DI,1 SUB [DI], 1 MOV AL,10 MUL [DI] ADD [SI], AX When the input is two digits, ten digits multiply 10 plus SUB AH,AH JMP LLP1 LP: MOV BH, [SI]; give the number of loops to BH MOV AL,BL INC BL MUL BL; BL (plus 1) and AL (original value) multiply to AX ADD CX,AX; AX and CX add to CX to accumulate JO OOF through loops; re-enter CMP BH,BL if overflow Determine whether the N value JNZ LP MOV AX,CX MOV CX,0AH MOV BX,0 LOP:MOV DX,0 DIV CX is reached; the 32-bit number represented by AX is divided by 10, the quotient is placed in AX, and the remainder is placed in DX INC BX ADD DX,30H PUSH DX; the remainder is pushed into the stack CMP AX,0 JNZ LOP in turn If the quotient is not 0, continue to divide 10 LEA DX,result MOV AH,9 INT 21H; DOS function call, output string OUTPUT: POP DX MOV AH,2 INT 21H; data in DX is out of stack in turn and display DEC BX JNZ OUTPUT; stop JMP STATE OOF:LEA DX,over MOV AH,09H INT 21H after destack is complete DOS function call, overflow display JMP STATE CODE ENDSEND STATE5.4 program running results and analysis:

The multiplication and accumulation calculation can be obtained step by step according to the flow chart, and there is trouble in inputting two digits and converting the result to decimal output. by searching the data and trying constantly, we finally find a simple solution, that is, shift and accumulate when two digits are input. the output divided by 10 is stored in the stack and displayed in turn.

Fig. 5 calculation of the design results of Seven 1 × 3 × 3 × 4 × 5 + N (Numb1)

6. Calculate the design requirements for Null 6.1:

Master the method of realizing mathematical functions in high-level language in assembly language. A program is designed to realize the algorithm of mathematical formula Numbai N (Nmur1) (NMur2) 2 * 1. The value N is inputted by the keyboard and the calculation result is output at the display terminal. Design requirements: the range of N is 0-65535, that is, the storage capacity of 16-bit registers is not exceeded.

6.2 Design ideas:

Enter the N value, realize the factorial through a loop and store the calculation results in AX, and then convert the hexadecimal to decimal output.

Please Input N (1-8): ",'$'result DB 0AHJ 0DH," the results is: ",' $'over DB 0AHJ 0DH," overflow! ", 0AHJ 0DH ENDS STACK SEGMENT SSTACK DB 0DH (0) STACK ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACK STATE: MOV AX,DATA MOV DS,AX Segment initialization LEA DX,pkey MOV AH,09H INT 21H; DOS function call, display string MOV AH,1 INT 21H; DOS function call, enter N SUB AL,30H CMP AL,08H JA OOF; input greater than 8 overflow XOR AH,AH MOV BP,AX Assign the cyclic count value N to BP LP: MOV BX,BP DEC BX JZ LLP; if the factorial number is BX,BX 0, you must jump to MUL BX immediately; AX stores the factorial result (for hexadecimal to decimal) DEC BP JNZ LP LLP: MOV CX,0 MOV BX,10 LLLP: MOV DX,0 DIV BX The 32-bit number represented by AX is divided by 10, the quotient is put in AX, and the remainder is put in DX ADD DX,30H PUSH DX; the remainder is converted to ASCII code value and pressed into the stack INC CX CMP AX,0; if the quotient is not 0, continue to divide 10 JNZ LLLP MOV AH,09H LEA DX,result INT 21H DOS function call, output string LOP: POP DX MOV AH,2 INT 21H; DX each out of stack and display LOOP LOP JMP STATE OOF: LEA DX,over MOV AH,09H INT 21H DOS function call, overflow display JMP STATE CODE ENDS END STATE6.4 program running results and analysis:

The factorial part uses the MUL instruction AX to store the calculation results and realize the factorial. Except for the factorial calculation part, the other parts are similar to the fifth question. The same result encountered trouble when converting to decimal output, which is realized by dividing 10 into the stack and then taking it out and displaying it in turn.

Figure 6 calculates N! Design result

At this point, the study of "how to realize simple mathematical operations in assembly language" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report