nya
This commit is contained in:
		
							parent
							
								
									bcf24631d4
								
							
						
					
					
						commit
						89cd73673d
					
				
					 4 changed files with 213 additions and 0 deletions
				
			
		
							
								
								
									
										64
									
								
								asm/idiv.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								asm/idiv.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,64 @@ | |||
| 	.file	"idiv.c" | ||||
| 	.intel_syntax noprefix
 | ||||
| 	.text | ||||
| 	.section	.rodata | ||||
| .LC0: | ||||
| 	.string	"%hd %hd" | ||||
| .LC1: | ||||
| 	.string	"%hd\n" | ||||
| 	.text | ||||
| 	.globl	main
 | ||||
| 	.type	main, @function
 | ||||
| main: | ||||
| .LFB0: | ||||
| 	.cfi_startproc | ||||
| 	push	rbp | ||||
| 	.cfi_def_cfa_offset 16
 | ||||
| 	.cfi_offset 6, -16 | ||||
| 	mov	rbp, rsp | ||||
| 	.cfi_def_cfa_register 6
 | ||||
| 	sub	rsp, 16 | ||||
| 	mov	rax, QWORD PTR fs:40 | ||||
| 	mov	QWORD PTR -8[rbp], rax | ||||
| 	xor	eax, eax | ||||
| 	lea	rdx, -12[rbp] | ||||
| 	lea	rax, -14[rbp] | ||||
| 	mov	rsi, rax | ||||
| 	lea	rax, .LC0[rip] | ||||
| 	mov	rdi, rax | ||||
| 	mov	eax, 0 | ||||
| 	call	__isoc99_scanf@PLT
 | ||||
| 	movzx	eax, WORD PTR -14[rbp] | ||||
| 	movzx	edx, WORD PTR -12[rbp] | ||||
| #APP | ||||
| # 6 "idiv.c" 1 | ||||
| 	mov ax,%ax | ||||
| mov dx,%bx | ||||
| cwd | ||||
| idiv %bx | ||||
| mov %ax, %dx | ||||
| mov %dx, ax | ||||
| 
 | ||||
| # 0 "" 2 | ||||
| #NO_APP | ||||
| 	mov	WORD PTR -10[rbp], ax | ||||
| 	movsx	eax, WORD PTR -10[rbp] | ||||
| 	mov	esi, eax | ||||
| 	lea	rax, .LC1[rip] | ||||
| 	mov	rdi, rax | ||||
| 	mov	eax, 0 | ||||
| 	call	printf@PLT
 | ||||
| 	mov	eax, 0 | ||||
| 	mov	rdx, QWORD PTR -8[rbp] | ||||
| 	sub	rdx, QWORD PTR fs:40 | ||||
| 	je	.L3 | ||||
| 	call	__stack_chk_fail@PLT
 | ||||
| .L3: | ||||
| 	leave | ||||
| 	.cfi_def_cfa 7, 8 | ||||
| 	ret | ||||
| 	.cfi_endproc | ||||
| .LFE0: | ||||
| 	.size	main, .-main | ||||
| 	.ident	"GCC: (GNU) 11.2.0" | ||||
| 	.section	.note.GNU-stack,"",@progbits
 | ||||
							
								
								
									
										19
									
								
								asm/switch.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								asm/switch.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| int main() { | ||||
| 	int x = 1; | ||||
| 	switch(x) { | ||||
| 		case 1:  | ||||
| 			return 1; | ||||
| 			break; | ||||
| 		case 2: | ||||
| 			return 2; | ||||
| 			break; | ||||
| 		case 3: | ||||
| 		case 4: | ||||
| 			return 113; | ||||
| 		case 5: | ||||
| 			return 4; | ||||
| 			break; | ||||
| 		case 6: | ||||
| 			return  | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										42
									
								
								asm/switch.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								asm/switch.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,42 @@ | |||
| 	.file	"switch.c" | ||||
| 	.text | ||||
| 	.globl	main
 | ||||
| 	.type	main, @function
 | ||||
| main: | ||||
| .LFB0: | ||||
| 	.cfi_startproc | ||||
| 	pushq	%rbp | ||||
| 	.cfi_def_cfa_offset 16
 | ||||
| 	.cfi_offset 6, -16 | ||||
| 	movq	%rsp, %rbp | ||||
| 	.cfi_def_cfa_register 6
 | ||||
| 	movl	$1, -4(%rbp) | ||||
| 	cmpl	$4, -4(%rbp) | ||||
| 	jg	.L2 | ||||
| 	cmpl	$3, -4(%rbp) | ||||
| 	jge	.L3 | ||||
| 	cmpl	$1, -4(%rbp) | ||||
| 	je	.L4 | ||||
| 	cmpl	$2, -4(%rbp) | ||||
| 	je	.L5 | ||||
| 	jmp	.L2 | ||||
| .L4: | ||||
| 	movl	$1, %eax | ||||
| 	jmp	.L6 | ||||
| .L5: | ||||
| 	movl	$2, %eax | ||||
| 	jmp	.L6 | ||||
| .L3: | ||||
| 	movl	$113, %eax | ||||
| 	jmp	.L6 | ||||
| .L2: | ||||
| 	movl	$0, %eax | ||||
| .L6: | ||||
| 	popq	%rbp | ||||
| 	.cfi_def_cfa 7, 8 | ||||
| 	ret | ||||
| 	.cfi_endproc | ||||
| .LFE0: | ||||
| 	.size	main, .-main | ||||
| 	.ident	"GCC: (GNU) 11.2.0" | ||||
| 	.section	.note.GNU-stack,"",@progbits
 | ||||
							
								
								
									
										88
									
								
								nasm/P.asm
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								nasm/P.asm
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,88 @@ | |||
| extern scanf | ||||
| extern printf  | ||||
| global main | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| section .text | ||||
| meow:	 | ||||
| 	fld qword [x + 8 * ebx] | ||||
| 	fld qword [n] | ||||
| 	fcomp  | ||||
| 	fstsw ax | ||||
| 	sahf | ||||
| 	jnbe end | ||||
| 	fld qword [n] | ||||
| 	fxch | ||||
| 	fsubr  | ||||
| 
 | ||||
| 	fld qword [s] | ||||
| 	fadd  | ||||
| 	fstp qword [s] | ||||
| 
 | ||||
| 	fld qword [x + 8 * ebx] | ||||
| 
 | ||||
| 	fld qword [q] | ||||
| 	fxch | ||||
| 	fdivr | ||||
| 
 | ||||
| 	inc ebx | ||||
| 
 | ||||
| 	fstp qword [x + 8 * ebx] | ||||
| 
 | ||||
| 	call meow | ||||
| 	dec ebx | ||||
| 
 | ||||
| 	fld qword [x + 8 * ebx] | ||||
| 
 | ||||
| 	fld qword [w] | ||||
| 	fxch | ||||
| 	fdivr | ||||
| 	inc ebx | ||||
| 
 | ||||
| 	fstp qword [x + 8 * ebx] | ||||
| 
 | ||||
| 	call meow | ||||
| 
 | ||||
| 	dec ebx | ||||
| 
 | ||||
| 	ret | ||||
| 
 | ||||
| end: | ||||
| 	sub esp, 4 | ||||
| 	fstp dword [esp] | ||||
| 	add esp, 4 | ||||
| 
 | ||||
| 	ret | ||||
| 
 | ||||
| main: | ||||
| 
 | ||||
| 	xor ebx, ebx | ||||
| 	push x | ||||
| 	push i | ||||
| 	call scanf | ||||
| 	add esp, 8 | ||||
| 	 | ||||
| 	call meow | ||||
| 
 | ||||
| 	fld qword [s] | ||||
| 	sub esp, 8 | ||||
| 	fstp qword [esp] | ||||
| 	push o | ||||
| 	call printf | ||||
| 	add esp, 12 | ||||
| 
 | ||||
| 	xor eax, eax | ||||
| 	ret | ||||
| 
 | ||||
| section .data | ||||
| i db "%lf", 0 | ||||
| o db "%.10lf", 10, 13, 0 | ||||
| 
 | ||||
| s dq 0.0 | ||||
| n dq 1.0 | ||||
| q dq 2.0 | ||||
| w dq 3.0 | ||||
| 
 | ||||
| section .bss | ||||
| x resq 100000 | ||||
		Reference in a new issue