Last active
June 6, 2021 09:55
-
-
Save jin-x/6ae12d6df3cc55d2ad0256584b7ba4d0 to your computer and use it in GitHub Desktop.
@jinxonik / UniLecs #86 (2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
format PE64 Console 5.0 | |
include 'win64axp.inc' | |
;-- CODE SECTION ------------------------------------------------------------------------------------------------------- | |
.code | |
entry: | |
frame | |
ldmxcsr [MXCSR] | |
cinvoke printf, 'Enter width and height of rectangle: ' | |
cinvoke scanf, _fmt_lf | |
xorpd xmm6,xmm6 ; xmm6 = 0 | |
comisd xmm0,xmm6 | |
jbe .wrong ; wrong or <= 0 | |
movsd xmm7,xmm0 | |
cinvoke scanf, _fmt_lf | |
comisd xmm0,xmm6 | |
jbe .wrong ; wrong or <= 0 | |
movsd xmm1,xmm7 | |
stdcall Sqr3SideInRect | |
movq rdx,xmm0 | |
cinvoke printf, <'Square side size = %g',13,10>, rdx | |
.exit: | |
invoke ExitProcess, 0 | |
.wrong: | |
cinvoke printf, <'Wrong or not positive number!',13,10> | |
jmp .exit | |
endf | |
; Get maximum side size of three squares inside rectangle with specified width and height | |
Sqr3SideInRect: ; x in xmm0, y in xmm1 | |
; assume: | |
; length (of rectangle) = maximum of x and y | |
; width (of rectangle) = minimum of x and y | |
; | |
; if width divided by 2 is more than | |
; minimum of (length divided by 3) and width | |
; we'll cut by this scheme: | |
; +-----+-----+--+ | |
; |#####|#####| | | |
; |#####|#####| | | |
; +-----+-----+--+ | |
; |#####| | | |
; |#####| | | |
; +-----+--------+ | |
; else we'll cut by this scheme: | |
; +-----+-----+-----+ | |
; |#####|#####|#####| | |
; |#####|#####|#####| | |
; +-----+-----+-----+ | |
; | | | |
; +-----------------+ | |
movsd xmm2,xmm0 ; xmm2 = x | |
minsd xmm0,xmm1 ; xmm0 = min(x, y) | |
maxsd xmm1,xmm2 ; xmm1 = max(x, y) | |
divsd xmm1,[_num3] ; xmm1 = max(x, y)/3 | |
movsd xmm2,xmm0 ; xmm2 = min(x, y) | |
minsd xmm1,xmm2 ; xmm1 = min(max(x, y)/3, min(x, y)) | |
divsd xmm0,[_num2] ; xmm0 = min(x, y)/2 | |
maxsd xmm0,xmm1 ; xmm0 = max(min(x, y)/2, min(max(x, y)/3, min(x, y))) | |
ret ; return xmm0 | |
;-- DATA SECTION ------------------------------------------------------------------------------------------------------- | |
.data | |
_num2 dq 2.0 | |
_num3 dq 3.0 | |
MXCSR dd 1F80h | |
_fmt_lf db '%lf',0 | |
;-- IMPORT SECTION ----------------------------------------------------------------------------------------------------- | |
section '.idata' import data readable | |
library kernel32, 'kernel32.dll',\ | |
msvcrt, 'msvcrt.dll' | |
import kernel32,\ | |
ExitProcess, 'ExitProcess' | |
import msvcrt,\ | |
printf, 'printf',\ | |
scanf, 'scanf' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment