1 / 13

87 examples

87 examples. Getting sqrt. call readint fstcw control;;;store current control word or control,0800h;set bit 11 clear bit 10 to round up fldcw control;;load new control word mov num,eax fild num fsqrt fistp sqr fwait mov edx, offset prompt2 call writestring mov eax,sqr call writeint.

boyd
Télécharger la présentation

87 examples

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 87 examples

  2. Getting sqrt call readint fstcw control;;;store current control word or control,0800h;set bit 11 clear bit 10 to round up fldcw control;;load new control word mov num,eax fild num fsqrt fistp sqr fwait mov edx, offset prompt2 call writestring mov eax,sqr call writeint

  3. Rounding set to round up • c:\Masm615>primes • enter an integer125 • sqrt of integer+12

  4. Add code to check for prime and print divisors for composites mov eax,num call crlf mov ebx,2;;;first divisor top: xor edx,edx push eax div ebx;;divide mov divi,ebx cmp edx,0 je notprime inc ebx cmp ebx,sqr jg prime pop eax jmp top notprime: call writedec call crlf mov eax,divi call writedec call crlf mov edx,offset f call writestring prime: mov edx,offset t call writestring

  5. Output from primes enter an integer1337711 18841 71 not a prime c:\Masm615>primes enter an integer17171731 746597 23 not a prime c:\Masm615>primes enter an integer313713 104571 3 not a prime c:\Masm615>primes enter an integer313717 prime c:\Masm615>

  6. factorials call readint mov num,eax call crlf fld1 ;;load a 1 for subtacting and comparing..this will be st(2) fld1 ;;prod value initialized in st(1) fild num;;;multiplier... need to count down and multiply st by st(1) theloop: ftst ;;is st==0? fstsw status and status, 4100h;check bits c3 and c0...c3=0 c0=1 means st<source cmp status,4000h;;st==source jz done fmul st(1),st ;;leave prod in st(1) fsub st,st(2) jmp theloop done: fistp dummy fistp answer mov edx,offset p2 call writestring call crlf fwait mov eax,answer call writedec

  7. factorials c:\Masm615>factorials enter an integer6 factorial is 720 c:\Masm615>factorials enter an integer7 factorial is 5040 c:\Masm615>factorials enter an integer20 factorial is 2147483648 c:\Masm615>

  8. Fibonacci values mov edx, offset prompt call crlf call writestring call readint call crlf fld1 ;;load a 1 for subtacting and comparing..this will be st(2) fld1 ;;prod value initialized in st(1) top: cmp eax,0 je done fadd st(1),st fsubr st,st(1) ;;;reverse subtract!!!! cute huhn?st=st(1)-st dec eax jmp top done: fistp dummy fistp answer mov edx,offset p2 call writestring call crlf fwait mov eax,answer call writedec

  9. Fibonacci c:\Masm615>fibs enter an integer4 fib is 8 c:\Masm615>fibs enter an integer6 fib is 21 c:\Masm615>fibs enter an integer7 fib is 34 c:\Masm615>fibs enter an integer100 fib is 2147483648 c:\Masm615>

  10. Mimicking real io • You can output reals by outputting first the integer part, subtracting this from the original value, then repeatedly multiplying the fraction by ten, (subtracting this off from the remainder) and outputting this sequence of fractional digits. • This is NOT an IEEE f-p conversion routine!

  11. Rounding control & the int part fstcw control or control,0C00h ;;;chop or truncate fldcw control fild ten ;;ten is in st(1) fild num ;;num is in st(0) fsqrt ;;sqrt in st fist intsqr ;;;store chopped result, don’t pop call crlf mov edx,offset message call writestring fwait mov ax,intsqr ;;write the int part call writedec

  12. realio mov edx,offset dot;;decimal point call writestring fisub intsqr ;;subtract from sqrt the int part leaving fractional part ;now loop & store 5 decimal places mov edi, offset decimals mov ecx, 5 up: fmul st,st(1) ;;multiply by 10 to shift dec point fist digit ;store truncated int fisub digit ;;subtract it off of the total fwait mov ax,digit add al,48 mov byte ptr [edi],al ;;store this digit inc edi loop up

  13. Run of realio c:\Masm615>realio enter an integer: 121 sqrt of integer 11.00000 c:\Masm615>realio enter an integer: 123 sqrt of integer 11.09053 c:\Masm615>realio enter an integer: 143 sqrt of integer 11.95826 c:\Masm615>

More Related