file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/521962.c
#ifdef STM32F3xx #include "stm32f3xx_ll_opamp.c" #endif #ifdef STM32L1xx #include "stm32l1xx_ll_opamp.c" #endif #ifdef STM32L4xx #include "stm32l4xx_ll_opamp.c" #endif
the_stack_data/1170655.c
#include <stdio.h> #include <omp.h> #define NTHREADS 4 #define CBLK 8 static long num_steps = 100000000; double step; int main () { int i, j, actual_nthreads; double pi, start_time, run_time; double sum[NTHREADS][CBLK]={0.0}; step = 1.0 / (double) num_steps; omp_set_num_threads(NTHREADS); start_time = omp_get_wtime(); #pragma omp parallel { int i; int id = omp_get_thread_num(); int numthreads = omp_get_num_threads(); double x; if (id == 0) actual_nthreads = numthreads; for (i = id; i < num_steps; i += numthreads) { x = (i + 0.5) * step; sum[id][0] += 4.0 / (1.0 + x * x); } } // end of parallel region pi = 0.0; for (i = 0; i < actual_nthreads; i++) pi += sum[i][0]; pi = step * pi; run_time = omp_get_wtime() - start_time; printf("\n pi is \%f in \%f seconds \%d thrds \n", pi,run_time,actual_nthreads); }
the_stack_data/141880.c
#include <stdlib.h> #include <stdio.h> main(int argc, char *argv[]) { if(argc != 3) return EXIT_FAILURE; FILE *first = fopen(argv[1], "r"), *second = fopen(argv[2], "r"); if(first == NULL || second == NULL) { if(first == NULL) fprintf(stderr, "error: could not open file %s\n", argv[1]); else if(second == NULL) fprintf(stderr, "error: could not open file %s\n", argv[2]); if(first != NULL) fclose(first); if(second != NULL) fclose(second); return EXIT_FAILURE; } char f, s; size_t len = 0; while((f = fgetc(first)) != EOF && (s = fgetc(second)) != EOF) if(f == s) { fputc(f, stdout); ++len; } else break; printf("\n%lu\n", len); fclose(first); fclose(second); }
the_stack_data/7951006.c
// Name : Junhong Wang // ID : 504941113 // Email : [email protected] #include <pthread.h> #include <time.h> #include <getopt.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #define BILLION 1000000000L pthread_t *tids; int opt_yield = 0; int opt_sync = 0; int s_lock = 0; pthread_mutex_t m_lock; char sync_method; char tag[100] = ""; struct ThreadInfo { long long *counter; int iterations; }; void add(long long *pointer, long long value) { long long sum = *pointer + value; if (opt_yield) sched_yield(); *pointer = sum; } void mutex_add(long long *pointer, long long value) { pthread_mutex_lock(&m_lock); add(pointer, value); pthread_mutex_unlock(&m_lock); } void spin_add(long long *pointer, long long value) { while (__sync_lock_test_and_set(&s_lock, 1)); add(pointer, value); __sync_lock_release(&s_lock); } void atomic_add(long long *pointer, long long value) { // no longer using origianl add function long long expectedCounter; long long newCounter; do { expectedCounter = *pointer; newCounter = expectedCounter + value; if (opt_yield) sched_yield(); } while (__sync_val_compare_and_swap(pointer, expectedCounter, newCounter) != expectedCounter); } char* get_usage() { return "\ Usage: ./lab2a_add [OPTION]...\n\ Starts the specified number of threads,\n\ each of which will use the above add function to\n\ 1. add 1 to the counter the specified number of times\n\ 2. add -1 to the counter the specified number of times\n\ 3. exit to re-join the parent thread\n\ Then prints to stdout a comma-separated-value (CSV) record.\n\ \n\ --threads=NUMBER takes a parameter for the number of\n\ parallel threads (default 1)\n\ --iterations=NUMBER takes a parameter for the number of\n\ iterations (default 1)\n\ --yield cause a thread to immediately yield\n\ --sync=TYPE execute with synchronization\n\ use mutex if TYPE=m\n\ use spin-lock if TYPE=s\n\ use compare-and-swap if TYPE=c\n\ "; } void thread_handle_loop(long long *counter, int iterations, int value) { int i; for (i = 0; i < iterations; i++) { if (opt_sync) { if (sync_method == 'm') mutex_add(counter, value); else if (sync_method == 's') spin_add(counter, value); else if (sync_method == 'c') atomic_add(counter, value); } else { add(counter, value); } } } void* thread_function(void *threadInfo) { struct ThreadInfo *info = (struct ThreadInfo*) threadInfo; thread_handle_loop(info->counter, info->iterations, 1); thread_handle_loop(info->counter, info->iterations, -1); return NULL; } void handle_yield_tag() { if (opt_yield) strcat(tag, "-yield"); } void handle_sync_tag() { if (opt_sync) { if (sync_method == 'm') strcat(tag, "-m"); else if (sync_method == 's') strcat(tag, "-s"); else if (sync_method == 'c') strcat(tag, "-c"); } else { strcat(tag, "-none"); } } char* get_tag() { strcat(tag, "add"); handle_yield_tag(); handle_sync_tag(); return tag; } int is_sync_method_valid(char sync_method) { return sync_method == 'm' || sync_method == 's' || sync_method == 'c'; } void handle_unrecognized_argument() { fprintf(stderr, "Unrecognized argument detected\n%s\n", get_usage()); exit(1); } void initialize_mutex() { if (pthread_mutex_init(&m_lock, NULL)) { fprintf(stderr, "Error initializing mutex\n"); exit(1); } } void handle_sync_option(char *optarg) { opt_sync = 1; sync_method = optarg[0]; if (!is_sync_method_valid(sync_method)) handle_unrecognized_argument(); if (sync_method == 'm') initialize_mutex(); } void handle_options(int argc, char **argv, int *numThreads, int *numIterations) { int option; struct option options[] = { {"threads", required_argument, NULL, 't'}, // takes a parameter for the number of parallel threads (--threads=#, default 1). {"iterations", required_argument, NULL, 'i'}, // takes a parameter for the number of iterations (--iterations=#, default 1). {"yield", no_argument, NULL, 'y'}, // Add a new --yield to your driver program that sets opt_yield to 1 {"sync", required_argument, NULL, 's'}, // synchronization option {0, 0, 0, 0} }; while (1) { option = getopt_long(argc, argv, "", options, NULL); if (option == -1) break; switch (option) { case 't': *numThreads = atoi(optarg); break; case 'i': *numIterations = atoi(optarg); break; case 'y': opt_yield = 1; break; case 's': handle_sync_option(optarg); break; default: handle_unrecognized_argument(); } } } long long get_num_operations(int numThreads, int numIterations) { return numThreads * numIterations * 2; } long long get_run_time(struct timespec *start, struct timespec *end) { return BILLION * (end->tv_sec - start->tv_sec) + end->tv_nsec - start->tv_nsec; } long long get_average_time_per_operation(long long runTime, long long numOperations) { return runTime / numOperations; } void free_tids() { free(tids); } void safe_pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) { if (pthread_create(thread, attr, start_routine, arg) != 0) { fprintf(stderr, "Error creating a thread\n"); exit(1); } } void safe_pthread_join(pthread_t thread, void **retval) { if (pthread_join(thread, retval) != 0) { fprintf(stderr, "Error joining a thread\n"); exit(1); } } void check_malloc_error(void *ptr) { if (ptr == NULL) { fprintf(stderr, "Error allocating memory\n"); exit(1); } } void initialize_tids(int numThreads) { tids = (pthread_t*) malloc(sizeof(pthread_t) * numThreads); check_malloc_error(tids); atexit(free_tids); } void handle_threads(long long *counter, int numThreads, int numIterations) { int i; initialize_tids(numThreads); struct ThreadInfo info; info.counter = counter; info.iterations = numIterations; for (i = 0; i < numThreads; i++) safe_pthread_create(&tids[i], NULL, thread_function, (void*) &info); for (i = 0; i < numThreads; i++) safe_pthread_join(tids[i], NULL); } void handle_report(long long counter, int numThreads, int numIterations, struct timespec *start, struct timespec *end) { long long numOperations = get_num_operations(numThreads, numIterations); long long runTime = get_run_time(start, end); printf( "%s,%d,%d,%lld,%lld,%lld,%lld\n", get_tag(), numThreads, numIterations, numOperations, runTime, get_average_time_per_operation(runTime, numOperations), counter ); } int main(int argc, char **argv) { long long counter = 0; int numThreads = 1; int numIterations = 1; struct timespec start, end; // set flags handle_options(argc, argv, &numThreads, &numIterations); // notes the (high resolution) starting time for the run (using clock_gettime(3)) clock_gettime(CLOCK_MONOTONIC, &start); // starts the specified number of threads, each of which will use the above add function handle_threads(&counter, numThreads, numIterations); // wait for all threads to complete, and notes the (high resolution) ending time for the run clock_gettime(CLOCK_MONOTONIC, &end); // prints to stdout a comma-separated-value (CSV) record handle_report(counter, numThreads, numIterations, &start, &end); exit(0); }
the_stack_data/600107.c
#include <stdio.h> #include <math.h> int main() { int lados; long double raio, per, angulo, pi = 3.14159265358979323846; scanf("%d\n%Lf", &lados, &raio); angulo = pi / lados; per = (2 * raio * sin(angulo)) * lados; printf("%.2Lf\n", per); return(0); }
the_stack_data/151704734.c
/** *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file isatty.c * * @brief _isatty funciton. * * @revision * Date Author Notes * 2020-02-20 OneOS Team First Version *********************************************************************************************************************** */ #include <unistd.h> int _isatty(int fd) { if (fd == STDOUT_FILENO || fd == STDERR_FILENO) return 1; return 0; }
the_stack_data/19179.c
#include <stdio.h> #define peso1 3.5 #define peso2 7.5 int main() { double nota1; double nota2; double media; scanf("%lf", &nota1); scanf("%lf", &nota2); nota1 *= peso1; nota2 *= peso2; media = nota1 + nota2; media /= (peso1 + peso2); printf("MEDIA = %.5lf\n", media); return 0; }
the_stack_data/247017708.c
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv[]) { setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); char buf[32]; printf("Hello!\n"); printf("Here I am: %p\n", printf); gets(buf); }
the_stack_data/14201617.c
#include <ctype.h> #include <stdio.h> // Program prepise eno tekstovno datoteko v drugo, // pri tem vse majhne crke spremeni v velike. main(int argc, char *args[]){ if(argc != 3){ fprintf(stderr, "Napacno stevilo argumentov\n"); return 1; } FILE *vhod, *izhod; //input, output vhod = fopen(args[1], "r"); //za birane dodatmo samo b zravn izhod = fopen(args[2], "w"); //za birane dodatmo samo b zravn if(vhod != NULL && izhod != NULL){ while(!feof(vhod)){ int c = fgetc(vhod); c = toupper(c); if ( c != EOF) fputc(c, izhod); } fclose(vhod); fclose(izhod); } else{ fprintf(stderr, "Napaka pri odpiranju datotek.\n"); return 1; } return 0; }
the_stack_data/36075383.c
#include <stdio.h> #define FRED 12 #define BLOGGS(x) (12*(x)) int test() { printf("%d\n", FRED); printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3)); return 0; } // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : int main () { int x; x = test(); printf("%d\n", x); return 0; }
the_stack_data/676981.c
/* UNIX V7 source code: see /COPYRIGHT or www.tuhs.org for details. */ /*modified for Commercial II*/ char Bw[256-32] = { /*Times Bold widths*/ 12, /*space*/ 13, /*!*/ 0, /*"*/ 0, /*#*/ 18, /*$*/ 28, /*%*/ 27, /*&*/ 12, /*' close*/ 16, /*(*/ 16, /*)*/ 18, /***/ 36, /*+*/ 12, /*,*/ 14, /*- hyphen*/ 12, /*.*/ 18, /*/*/ 19+0200, /*0*/ 19+0200, /*1*/ 19+0200, /*2*/ 19+0200, /*3*/ 19+0200, /*4*/ 19+0200, /*5*/ 19+0200, /*6*/ 19+0200, /*7*/ 19+0200, /*8*/ 19+0200, /*9*/ 13, /*:*/ 13, /*;*/ 0, /*<*/ 36, /*=*/ 0, /*>*/ 22, /*?*/ 0, /*@*/ 28+0200, /*A*/ 26+0200, /*B*/ 26+0200, /*C*/ 29+0200, /*D*/ 25+0200, /*E*/ 23+0200, /*F*/ 28+0200, /*G*/ 32+0200, /*H*/ 16+0200, /*I*/ 21+0200, /*J*/ 28+0200, /*K*/ 25+0200, /*L*/ 36+0200, /*M*/ 30+0200, /*N*/ 29+0200, /*O*/ 25+0200, /*P*/ 29+0300, /*Q*/ 28+0200, /*R*/ 23+0200, /*S*/ 25+0200, /*T*/ 29+0200, /*U*/ 27+0200, /*V*/ 36+0200, /*W*/ 27+0200, /*X*/ 28+0200, /*Y*/ 27+0200, /*Z*/ 12, /*[*/ 0, /*\*/ 12, /*]*/ 0, /*^*/ 0, /*_*/ 12, /*` open*/ 19, /*a*/ 19+0200, /*b*/ 16, /*c*/ 19+0200, /*d*/ 17, /*e*/ 13+0200, /*f*/ 18+0100, /*g*/ 22+0200, /*h*/ 12+0200, /*i*/ 12+0300, /*j*/ 23+0200, /*k*/ 12+0200, /*l*/ 32, /*m*/ 22, /*n*/ 18, /*o*/ 20+0100, /*p*/ 19+0100, /*q*/ 15, /*r*/ 17, /*s*/ 13+0200, /*t*/ 21, /*u*/ 19, /*v*/ 27, /*w*/ 21, /*x*/ 19+0100, /*y*/ 17, /*z*/ 0, /*{*/ 2, /*|*/ 0, /*}*/ 0, /*~*/ 6, /*narrow space*/ 14, /*hyphen*/ 27, /*bullet*/ 27, /*square*/ 36, /*3/4 em*/ 18, /*rule*/ 28, /*1/4*/ 28, /*1/2*/ 28, /*3/4*/ 36, /*minus*/ 22, /*fi*/ 22, /*fl*/ 23, /*ff*/ 33, /*ffi*/ 33, /*ffl*/ 15, /*degree*/ 20, /*dagger*/ 0, /*section*/ 9, /*foot mark*/ 0, /*'*/ 0, /*`*/ 0, /*_*/ 0, 3, /*half nar sp*/ 0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0, 20, /*registered*/ 20, /*copywrite*/ 0, 19, /*cent*/ };
the_stack_data/103264724.c
#include <stdio.h> // Should print an integer: number of spaces / 0 for tabs // In case of error, just guess 4 int main(int argc, char **argv) { if (argc < 2) { printf("4"); return 1; } FILE *fp = fopen(argv[1], "r"); if (fp == NULL) { printf("4"); return 1; } char line[80]; // We will process at most 79 characters of each line int line_num = 0; int num_lines_with_tabs = 0; unsigned short int num_spaces[1000]; // We will process at most 1000 lines for (int i = 0; i < 1000; i++) num_spaces[i] = 0; for (line_num = 0; line_num < 1000 && !feof(fp); line_num++) { fgets(line, 80, fp); for (int i = 0; i < 80; i++) { switch (line[i]) { case '\0': case '\n': goto next_line; case '\t': num_spaces[line_num] = -1; num_lines_with_tabs++; break; case ' ': num_spaces[line_num]++; break; default: goto next_line; } } next_line: continue; } int num_indented_lines = 0; for (int i = 0; i < line_num; i++) { if (num_spaces[i] != 0) { num_indented_lines++; } } if (num_lines_with_tabs > num_indented_lines / 2) { printf("0"); } else { // Assume the indent size is between 2 and 8 // Find the Highest one which fits >80% of lines for (int i = 8; i >= 2; i--) { int num_ok = 0; for (int j = 0; j < line_num; j++) { if (num_spaces[j] > 0 && num_spaces[j] % i == 0) { num_ok++; } } if (num_ok > num_indented_lines * 0.8) { printf("%d", i); return 0; } } // Default case, just guess 2 printf("2"); } fclose(fp); return 0; }
the_stack_data/110740.c
#include <math.h> // FIXME: use lanczos approximation double __lgamma_r(double, int *); double tgamma(double x) { int sign; double y; y = exp(__lgamma_r(x, &sign)); if (sign < 0) y = -y; return y; }
the_stack_data/215767902.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFFER_SIZE 512 int main(int argc, char *argv[]) { char temp[BUFFER_SIZE]; FILE *fp; if(argc < 3) { fprintf(stderr, "At least two arguments\n"); exit(EXIT_FAILURE); } if(!(fp = fopen(argv[2], "r"))) { fprintf(stderr, "Failed opening %s\n", argv[2]); exit(EXIT_FAILURE); } while(fgets(temp, BUFFER_SIZE, fp) && strstr(temp, argv[1])) fputs(temp, stdout); return 0; }
the_stack_data/137006.c
#include <stdio.h> int mat[8][8] = {0}; int out[64] = {0}; int n, tot = 0; void MT(int step, int x, int y); int main(void) { int x, y; printf("please input the size of the chessboard:"); scanf("%d", &n); printf("please input the coordinate of the knight(from 0 to size-1):"); scanf("%d %d", &x, &y); mat[x][y]=1; out[0]=x*10 + y; MT(1, x, y); printf("%d\n",tot); return 0; } void MT(int step, int x, int y) { if (step == n*n) { for(int i = 0;i < n*n;i++) printf("(%d,%d) ",out[i]/10, out[i]%10); putchar('\n'); tot++; } else for(int i = -2;i < 3;i++) for (int j = -2;j < 3;j++) { if((i+j)%2 && i && j) if(x+i>=0 && x+i<n && y+j>=0 && y+j<n) if(!mat[x+i][y+j]) { out[step] = (x+i)*10 + y+j; mat[x][y] = 1; MT(step+1, x+i, y+j); mat[x][y] = 0; } } }
the_stack_data/176706803.c
/* erl_comm.c */ #include <stdio.h> #include <unistd.h> typedef unsigned char byte; int read_exact(byte *buf, int len) { int i, got=0; do { if ((i = read(0, buf+got, len-got)) <= 0){ return(i); } got += i; } while (got<len); return(len); } int write_exact(byte *buf, int len) { int i, wrote = 0; do { if ((i = write(1, buf+wrote, len-wrote)) <= 0) return (i); wrote += i; } while (wrote<len); return (len); } int read_cmd(byte *buf) { int len; if (read_exact(buf, 2) != 2) return(-1); len = (buf[0] << 8) | buf[1]; return read_exact(buf, len); } int write_cmd(byte *buf, int len) { byte li; li = (len >> 8) & 0xff; write_exact(&li, 1); li = len & 0xff; write_exact(&li, 1); return write_exact(buf, len); }
the_stack_data/248579406.c
/*Exercise 4 - Functions Implement the three functions minimum(), maximum() and multiply() below the main() function. Do not change the code given in the main() function when you are implementing your solution.*/ #include <stdio.h> int minimum(int no1, int no2); int maximum(int no1, int no2); int multiply(int no1, int no2); int main() { int no1, no2; printf("Enter a value for no 1 : "); scanf("%d", &no1); printf("Enter a value for no 2 : "); scanf("%d", &no2); printf("%d ", minimum(no1, no2)); printf("%d ", maximum(no1, no2)); printf("%d ", multiply(no1, no2)); return 0; } int minimum(int no1, int no2) { if(no1<no2) { return no1; } else { return no2; } } int maximum(int no1, int no2) { if(no1>no2) { return no1; } else { return no2; } } int multiply(int no1, int no2) { return no1 * no2; }
the_stack_data/156394124.c
/* Copyright 2013-2019 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <stddef.h> void * start (void *arg) { /* "list" should show this line. */ return NULL; }
the_stack_data/26699870.c
#include <stdio.h> int main(){ int x=0; while(x<=100){ x++; if((x%2)==0){ printf("%d\n", x); } } return 0; }
the_stack_data/176704550.c
// Test if CSPGO instrumentation and use pass are invoked in lto. // // RUN: rm -rf %t && mkdir %t // RUN: llvm-profdata merge -o %t/noncs.profdata %S/Inputs/pgotestir.proftext // // Ensure Pass PGOInstrumentationGenPass is not invoked in PreLink. // RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata -fprofile-instrument=csllvm %s -flto -fdebug-pass-manager -emit-llvm-bc -o %t/foo_fe_pm.bc 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE // CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE: Running pass: PGOInstrumentationUse // CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE: Running pass: PGOInstrumentationGenCreateVar // CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-PRE-NOT: Running pass: PGOInstrumentationGen on // // Ensure Pass PGOInstrumentationGenPass is invoked in PostLink. // RUN: %clang_cc1 -O2 -x ir %t/foo_fe_pm.bc -fdebug-pass-manager -fprofile-instrument=csllvm -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST // CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST-NOT: Running pass: PGOInstrumentationUse // CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST: Running pass: PGOInstrumentationGen on // CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-POST-NOT: Running pass: PGOInstrumentationGenCreateVar // // RUN: llvm-profdata merge -o %t/cs.profdata %S/Inputs/pgotestir_cs.proftext // // Ensure Pass PGOInstrumentationUsePass is invoked Once in PreLink. // RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/cs.profdata %s -flto -fdebug-pass-manager -emit-llvm-bc -o %t/foo_fe_pm.bc 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE // CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE: Running pass: PGOInstrumentationUse // CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE-NOT: Running pass: PGOInstrumentationGenCreateVar // CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-PRE-NOT: Running pass: PGOInstrumentationUse // // Ensure Pass PGOInstrumentationUSEPass is invoked in PostLink. // RUN: %clang_cc1 -O2 -x ir %t/foo_fe_pm.bc -fdebug-pass-manager -fprofile-instrument-use-path=%t/cs.profdata -flto -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-POST // CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-POST: Running pass: PGOInstrumentationUse // CHECK-CSPGOUSEPASS-INVOKED-INSTR-USE-POST-NOT: Running pass: PGOInstrumentationUse
the_stack_data/12637596.c
/* * The following program is used to generate the constants for * computing sched averages. * * ============================================================== * C program (compile with -lm) * ============================================================== */ #include <math.h> #include <stdio.h> #define HALFLIFE 32 #define SHIFT 32 double y; void calc_runnable_avg_yN_inv(void) { int i; unsigned int x; printf("static const u32 runnable_avg_yN_inv[] = {"); for (i = 0; i < HALFLIFE; i++) { x = ((1UL<<32)-1)*pow(y, i); if (i % 6 == 0) printf("\n\t"); printf("0x%8x, ", x); } printf("\n};\n\n"); } int sum = 1024; void calc_runnable_avg_yN_sum(void) { int i; printf("static const u32 runnable_avg_yN_sum[] = {\n\t 0,"); for (i = 1; i <= HALFLIFE; i++) { if (i == 1) sum *= y; else sum = sum*y + 1024*y; if (i % 11 == 0) printf("\n\t"); printf("%5d,", sum); } printf("\n};\n\n"); } int n = -1; /* first period */ long max = 1024; void calc_converged_max(void) { long last = 0, y_inv = ((1UL<<32)-1)*y; for (; ; n++) { if (n > -1) max = ((max*y_inv)>>SHIFT) + 1024; /* * This is the same as: * max = max*y + 1024; */ if (last == max) break; last = max; } n--; printf("#define LOAD_AVG_PERIOD %d\n", HALFLIFE); printf("#define LOAD_AVG_MAX %ld\n", max); // printf("#define LOAD_AVG_MAX_N %d\n\n", n); } void calc_accumulated_sum_32(void) { int i, x = sum; printf("static const u32 __accumulated_sum_N32[] = {\n\t 0,"); for (i = 1; i <= n/HALFLIFE+1; i++) { if (i > 1) x = x/2 + sum; if (i % 6 == 0) printf("\n\t"); printf("%6d,", x); } printf("\n};\n\n"); } void main(void) { printf("/* Generated by Documentation/scheduler/sched-pelt; do not modify. */\n\n"); y = pow(0.5, 1/(double)HALFLIFE); calc_runnable_avg_yN_inv(); // calc_runnable_avg_yN_sum(); calc_converged_max(); // calc_accumulated_sum_32(); }
the_stack_data/73668.c
#include <stdio.h> #include <pthread.h> #include <stdlib.h> #include <unistd.h> void *fn_thread(void *arg) { printf("Hello from the thread\n"); sleep(2); printf("Bye bye from the thread\n"); pthread_exit((void *) 1); return NULL; } int main(int argc, char *argv[]) { pthread_t th; long retour; pthread_create(&th, NULL, fn_thread,NULL); pthread_join(th, (void*) &retour); printf("Valeur renvoyée: %ld\n", retour); printf("The end\n"); return 0; }
the_stack_data/15762488.c
#include <stdlib.h> int main(void) { system("eic -g -DTEST easter.c 1997"); system("eic -g -DTEST dblround.c 167.5678"); system("eic -g -DTEST factoryl.c"); system("eic -g -DTEST sstrdel.c"); system("eic -g -DTEST trim.c \" trim test\""); system("eic -g -DTEST amalloc.c"); return 0; } #ifdef EiCTeStS main(); #endif
the_stack_data/15763700.c
/* { dg-options { -nostartfiles below100.o -Tbelow100.ld -O2 } } */ /* { dg-final { scan-assembler "mov.b 32532,r" } } */ #define SFR (*((volatile unsigned char*)0x7f14)) unsigned char *p = (unsigned char *) 0x7f14; unsigned char yData = 0x12; void Do (void) { SFR = yData; } int main (void) { *p = 0x34; Do (); return (*p == 0x12) ? 0 : 1; }
the_stack_data/37637979.c
// // main.c // 14 // // Created by Никифоров Иван on 14.10.14. // Copyright (c) 2014 NIkif. All rights reserved. // #include <stdio.h> #include <string.h> #include <stdlib.h> int wcount(char *s) { int n, i, sum=0, a=0; n = (int)strlen(s); printf("n = %d\n", n); char *string; string=(char*)malloc(n*sizeof(char)); strncpy(string, s, n); printf("string = %s\n", string); if (n==0) { free(string); return 0; } if ((n==1)&&(string[0]!=' ')){ free(string); return 1; } if (string[0]!=' ') { sum+=1; } for (i=1; i<n; i++) { if ((string[i]!= ' ')&&(string[i-1]== ' ')) sum+=1; if(s[i]!=0) printf("%s -> %d\n", &s[i], sum); } if (sum!=0){ free(string); return sum; }else{ for (i=0; i<n; i++) { if (string[i]!= ' ') a+=1; } if (a!=0){ free(string); return 1; } } free(string); return sum; } // jg foh uiwduiwwi wodg y di wuy du wi int main(int argc, const char * argv[]) { char s; gets(&s); int n =wcount(&s); printf("%d", n); // int *d = wcount(&s); // free(d); return 0; }
the_stack_data/161079366.c
/** ****************************************************************************** * @file stm32g4xx_ll_usart.c * @author MCD Application Team * @brief USART LL module driver. ****************************************************************************** * @attention * * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_ll_usart.h" #include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ /** @addtogroup STM32G4xx_LL_Driver * @{ */ #if defined (USART1) || defined (USART2) || defined (USART3) || defined (UART4) || defined (UART5) /** @addtogroup USART_LL * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /** @addtogroup USART_LL_Private_Macros * @{ */ #define IS_LL_USART_PRESCALER(__VALUE__) (((__VALUE__) == LL_USART_PRESCALER_DIV1) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV2) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV4) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV6) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV8) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV10) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV12) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV16) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV32) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV64) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV128) \ || ((__VALUE__) == LL_USART_PRESCALER_DIV256)) /* __BAUDRATE__ The maximum Baud Rate is derived from the maximum clock available * divided by the smallest oversampling used on the USART (i.e. 8) */ #define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 18750000U) /* __VALUE__ In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d. */ #define IS_LL_USART_BRR_MIN(__VALUE__) ((__VALUE__) >= 16U) #define IS_LL_USART_DIRECTION(__VALUE__) (((__VALUE__) == LL_USART_DIRECTION_NONE) \ || ((__VALUE__) == LL_USART_DIRECTION_RX) \ || ((__VALUE__) == LL_USART_DIRECTION_TX) \ || ((__VALUE__) == LL_USART_DIRECTION_TX_RX)) #define IS_LL_USART_PARITY(__VALUE__) (((__VALUE__) == LL_USART_PARITY_NONE) \ || ((__VALUE__) == LL_USART_PARITY_EVEN) \ || ((__VALUE__) == LL_USART_PARITY_ODD)) #define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_7B) \ || ((__VALUE__) == LL_USART_DATAWIDTH_8B) \ || ((__VALUE__) == LL_USART_DATAWIDTH_9B)) #define IS_LL_USART_OVERSAMPLING(__VALUE__) (((__VALUE__) == LL_USART_OVERSAMPLING_16) \ || ((__VALUE__) == LL_USART_OVERSAMPLING_8)) #define IS_LL_USART_LASTBITCLKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_LASTCLKPULSE_NO_OUTPUT) \ || ((__VALUE__) == LL_USART_LASTCLKPULSE_OUTPUT)) #define IS_LL_USART_CLOCKPHASE(__VALUE__) (((__VALUE__) == LL_USART_PHASE_1EDGE) \ || ((__VALUE__) == LL_USART_PHASE_2EDGE)) #define IS_LL_USART_CLOCKPOLARITY(__VALUE__) (((__VALUE__) == LL_USART_POLARITY_LOW) \ || ((__VALUE__) == LL_USART_POLARITY_HIGH)) #define IS_LL_USART_CLOCKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_CLOCK_DISABLE) \ || ((__VALUE__) == LL_USART_CLOCK_ENABLE)) #define IS_LL_USART_STOPBITS(__VALUE__) (((__VALUE__) == LL_USART_STOPBITS_0_5) \ || ((__VALUE__) == LL_USART_STOPBITS_1) \ || ((__VALUE__) == LL_USART_STOPBITS_1_5) \ || ((__VALUE__) == LL_USART_STOPBITS_2)) #define IS_LL_USART_HWCONTROL(__VALUE__) (((__VALUE__) == LL_USART_HWCONTROL_NONE) \ || ((__VALUE__) == LL_USART_HWCONTROL_RTS) \ || ((__VALUE__) == LL_USART_HWCONTROL_CTS) \ || ((__VALUE__) == LL_USART_HWCONTROL_RTS_CTS)) /** * @} */ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup USART_LL_Exported_Functions * @{ */ /** @addtogroup USART_LL_EF_Init * @{ */ /** * @brief De-initialize USART registers (Registers restored to their default values). * @param USARTx USART Instance * @retval An ErrorStatus enumeration value: * - SUCCESS: USART registers are de-initialized * - ERROR: USART registers are not de-initialized */ ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx) { ErrorStatus status = SUCCESS; /* Check the parameters */ assert_param(IS_UART_INSTANCE(USARTx)); if (USARTx == USART1) { /* Force reset of USART clock */ LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_USART1); /* Release reset of USART clock */ LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_USART1); } else if (USARTx == USART2) { /* Force reset of USART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART2); /* Release reset of USART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART2); } else if (USARTx == USART3) { /* Force reset of USART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART3); /* Release reset of USART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART3); } #if defined(UART4) else if (USARTx == UART4) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART4); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART4); } #endif /* UART4 */ #if defined(UART5) else if (USARTx == UART5) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART5); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART5); } #endif /* UART5 */ else { status = ERROR; } return (status); } /** * @brief Initialize USART registers according to the specified * parameters in USART_InitStruct. * @note As some bits in USART configuration registers can only be written when * the USART is disabled (USART_CR1_UE bit =0), USART Peripheral should be in disabled state prior calling * this function. Otherwise, ERROR result will be returned. * @note Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0). * @param USARTx USART Instance * @param USART_InitStruct pointer to a LL_USART_InitTypeDef structure * that contains the configuration information for the specified USART peripheral. * @retval An ErrorStatus enumeration value: * - SUCCESS: USART registers are initialized according to USART_InitStruct content * - ERROR: Problem occurred during USART Registers initialization */ ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct) { ErrorStatus status = ERROR; uint32_t periphclk = LL_RCC_PERIPH_FREQUENCY_NO; /* Check the parameters */ assert_param(IS_UART_INSTANCE(USARTx)); assert_param(IS_LL_USART_PRESCALER(USART_InitStruct->PrescalerValue)); assert_param(IS_LL_USART_BAUDRATE(USART_InitStruct->BaudRate)); assert_param(IS_LL_USART_DATAWIDTH(USART_InitStruct->DataWidth)); assert_param(IS_LL_USART_STOPBITS(USART_InitStruct->StopBits)); assert_param(IS_LL_USART_PARITY(USART_InitStruct->Parity)); assert_param(IS_LL_USART_DIRECTION(USART_InitStruct->TransferDirection)); assert_param(IS_LL_USART_HWCONTROL(USART_InitStruct->HardwareFlowControl)); assert_param(IS_LL_USART_OVERSAMPLING(USART_InitStruct->OverSampling)); /* USART needs to be in disabled state, in order to be able to configure some bits in CRx registers */ if (LL_USART_IsEnabled(USARTx) == 0U) { /*---------------------------- USART CR1 Configuration --------------------- * Configure USARTx CR1 (USART Word Length, Parity, Mode and Oversampling bits) with parameters: * - DataWidth: USART_CR1_M bits according to USART_InitStruct->DataWidth value * - Parity: USART_CR1_PCE, USART_CR1_PS bits according to USART_InitStruct->Parity value * - TransferDirection: USART_CR1_TE, USART_CR1_RE bits according to USART_InitStruct->TransferDirection value * - Oversampling: USART_CR1_OVER8 bit according to USART_InitStruct->OverSampling value. */ MODIFY_REG(USARTx->CR1, (USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8), (USART_InitStruct->DataWidth | USART_InitStruct->Parity | USART_InitStruct->TransferDirection | USART_InitStruct->OverSampling)); /*---------------------------- USART CR2 Configuration --------------------- * Configure USARTx CR2 (Stop bits) with parameters: * - Stop Bits: USART_CR2_STOP bits according to USART_InitStruct->StopBits value. * - CLKEN, CPOL, CPHA and LBCL bits are to be configured using LL_USART_ClockInit(). */ LL_USART_SetStopBitsLength(USARTx, USART_InitStruct->StopBits); /*---------------------------- USART CR3 Configuration --------------------- * Configure USARTx CR3 (Hardware Flow Control) with parameters: * - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to * USART_InitStruct->HardwareFlowControl value. */ LL_USART_SetHWFlowCtrl(USARTx, USART_InitStruct->HardwareFlowControl); /*---------------------------- USART BRR Configuration --------------------- * Retrieve Clock frequency used for USART Peripheral */ if (USARTx == USART1) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE); } else if (USARTx == USART2) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART2_CLKSOURCE); } else if (USARTx == USART3) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART3_CLKSOURCE); } #if defined(UART4) else if (USARTx == UART4) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART4_CLKSOURCE); } #endif /* UART4 */ #if defined(UART5) else if (USARTx == UART5) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART5_CLKSOURCE); } #endif /* UART5 */ else { /* Nothing to do, as error code is already assigned to ERROR value */ } /* Configure the USART Baud Rate : - prescaler value is required - valid baud rate value (different from 0) is required - Peripheral clock as returned by RCC service, should be valid (different from 0). */ if ((periphclk != LL_RCC_PERIPH_FREQUENCY_NO) && (USART_InitStruct->BaudRate != 0U)) { status = SUCCESS; LL_USART_SetBaudRate(USARTx, periphclk, USART_InitStruct->PrescalerValue, USART_InitStruct->OverSampling, USART_InitStruct->BaudRate); /* Check BRR is greater than or equal to 16d */ assert_param(IS_LL_USART_BRR_MIN(USARTx->BRR)); } /*---------------------------- USART PRESC Configuration ----------------------- * Configure USARTx PRESC (Prescaler) with parameters: * - PrescalerValue: USART_PRESC_PRESCALER bits according to USART_InitStruct->PrescalerValue value. */ LL_USART_SetPrescaler(USARTx, USART_InitStruct->PrescalerValue); } /* Endif (=> USART not in Disabled state => return ERROR) */ return (status); } /** * @brief Set each @ref LL_USART_InitTypeDef field to default value. * @param USART_InitStruct pointer to a @ref LL_USART_InitTypeDef structure * whose fields will be set to default values. * @retval None */ void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct) { /* Set USART_InitStruct fields to default values */ USART_InitStruct->PrescalerValue = LL_USART_PRESCALER_DIV1; USART_InitStruct->BaudRate = 9600U; USART_InitStruct->DataWidth = LL_USART_DATAWIDTH_8B; USART_InitStruct->StopBits = LL_USART_STOPBITS_1; USART_InitStruct->Parity = LL_USART_PARITY_NONE ; USART_InitStruct->TransferDirection = LL_USART_DIRECTION_TX_RX; USART_InitStruct->HardwareFlowControl = LL_USART_HWCONTROL_NONE; USART_InitStruct->OverSampling = LL_USART_OVERSAMPLING_16; } /** * @brief Initialize USART Clock related settings according to the * specified parameters in the USART_ClockInitStruct. * @note As some bits in USART configuration registers can only be written when * the USART is disabled (USART_CR1_UE bit =0), USART Peripheral should be in disabled state prior calling * this function. Otherwise, ERROR result will be returned. * @param USARTx USART Instance * @param USART_ClockInitStruct pointer to a @ref LL_USART_ClockInitTypeDef structure * that contains the Clock configuration information for the specified USART peripheral. * @retval An ErrorStatus enumeration value: * - SUCCESS: USART registers related to Clock settings are initialized according * to USART_ClockInitStruct content * - ERROR: Problem occurred during USART Registers initialization */ ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct) { ErrorStatus status = SUCCESS; /* Check USART Instance and Clock signal output parameters */ assert_param(IS_UART_INSTANCE(USARTx)); assert_param(IS_LL_USART_CLOCKOUTPUT(USART_ClockInitStruct->ClockOutput)); /* USART needs to be in disabled state, in order to be able to configure some bits in CRx registers */ if (LL_USART_IsEnabled(USARTx) == 0U) { /* Ensure USART instance is USART capable */ assert_param(IS_USART_INSTANCE(USARTx)); /* Check clock related parameters */ assert_param(IS_LL_USART_CLOCKPOLARITY(USART_ClockInitStruct->ClockPolarity)); assert_param(IS_LL_USART_CLOCKPHASE(USART_ClockInitStruct->ClockPhase)); assert_param(IS_LL_USART_LASTBITCLKOUTPUT(USART_ClockInitStruct->LastBitClockPulse)); /*---------------------------- USART CR2 Configuration ----------------------- * Configure USARTx CR2 (Clock signal related bits) with parameters: * - Clock Output: USART_CR2_CLKEN bit according to USART_ClockInitStruct->ClockOutput value * - Clock Polarity: USART_CR2_CPOL bit according to USART_ClockInitStruct->ClockPolarity value * - Clock Phase: USART_CR2_CPHA bit according to USART_ClockInitStruct->ClockPhase value * - Last Bit Clock Pulse Output: USART_CR2_LBCL bit according to USART_ClockInitStruct->LastBitClockPulse value. */ MODIFY_REG(USARTx->CR2, USART_CR2_CLKEN | USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, USART_ClockInitStruct->ClockOutput | USART_ClockInitStruct->ClockPolarity | USART_ClockInitStruct->ClockPhase | USART_ClockInitStruct->LastBitClockPulse); } /* Else (USART not in Disabled state => return ERROR */ else { status = ERROR; } return (status); } /** * @brief Set each field of a @ref LL_USART_ClockInitTypeDef type structure to default value. * @param USART_ClockInitStruct pointer to a @ref LL_USART_ClockInitTypeDef structure * whose fields will be set to default values. * @retval None */ void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct) { /* Set LL_USART_ClockInitStruct fields with default values */ USART_ClockInitStruct->ClockOutput = LL_USART_CLOCK_DISABLE; USART_ClockInitStruct->ClockPolarity = LL_USART_POLARITY_LOW; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ USART_ClockInitStruct->ClockPhase = LL_USART_PHASE_1EDGE; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ USART_ClockInitStruct->LastBitClockPulse = LL_USART_LASTCLKPULSE_NO_OUTPUT; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ } /** * @} */ /** * @} */ /** * @} */ #endif /* USART1 || USART2 || USART3 || UART4 || UART5 */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/57949673.c
#include <stdio.h> int main() { int t = 2; printf("%d\n", t += 5 ); printf("%d\n", t *=10 ); printf("%d\n", t -= 6); printf("%d\n", t/=8); printf("%d\n", t %= 3); return 0; }
the_stack_data/165766030.c
int funca( int a ) { return a*a; } int funcb( int b ) { return funca( b ); } int main( int argc, char *argv[] ) { int a; int b; a = funca( 5 ); b = funcb( 5 ); }
the_stack_data/70449374.c
#include <stdio.h> #include <ctype.h> #define CHECK(PRED) printf("%s ... %s\n", (PRED) ? "Passed" : "Failed" , #PRED); size_t str_find_last(const char s[], int c); size_t str_replace_all(char s[], int oldc, int newc); int str_all_digits(const char s[]); int str_equal(const char s[], const char t[]); int main(void){ return 1; } /* Retruns the index of the last occurence of the character (scpecified by) c in the string s, or returns -1 if the string does not contain c. */ size_t str_find_last(const char s[], int c){ size_t i; size_t lastOccurance = -1; for(i = 0; s[i] != '\0'; i++){ if(s[i] == c){ lastOccurance = i; } } return lastOccurance; } /* Replaces all occurences of the character oldc in the string s by the character newc. Returns the number of replacments */ size_t str_replace_all(char s[], int oldc, int newc){ size_t i; int count = 0; for(i=0; s[i] !='\0'; i++){ if(s[i] == oldc){ oldc = newc; count++; } } return count; } /* Returns 1 if the string s consists entirely of digits; otwerwise, returns 0. */ int str_all_digits(const char s[]){ size_t i; for(i=0; s[i] !='\0'; i++){ if(!(isdigit(s[i]))){ return 0; } } return 1; } /* Returns 1 if the strings s and t have the same sequence of characters; otherwise, returns 0; */ int str_equal(const char s[], const char t[]){ size_t i; for(i=0; s[i] != '\0'; i++){ if(s[i] != t[i]){ return 0; } } return (t[i] == '\0'); }
the_stack_data/192329888.c
/* This software was developed at the National Institute of Standards and * Technology by employees of the Federal Government in the course of their * official duties. Pursuant to title 17 Section 105 of the United States * Code this software is not subject to copyright protection and is in the * public domain. NIST assumes no responsibility whatsoever for its use by * other parties, and makes no guarantees, expressed or implied, about its * quality, reliability, or any other characteristic. * We would appreciate acknowledgement if the software is used. * The SAMATE project website is: http://samate.nist.gov */ #include <stdlib.h> #include <stdio.h> #include <string.h> void doSomething(char *str) { if (!str) return; /* FIX */ str[0] = 'S'; } int main(int argc, char *argv[]) { char *str = (char *)NULL; if ((str = (char *)malloc(256*sizeof(char))) != NULL) { strcpy(str, "Falut!"); doSomething(str); printf("%s\n", str); free(str); str = NULL; doSomething(str); } return 0; }
the_stack_data/65295.c
#include <stdio.h> #include <stdbool.h> #define ARRSIZE 8 /* bubble sort */ int main(void) { int arr[ARRSIZE] = {6, 3, 8, 5, 2, 7, 4, 1};//{1, 2, 3, 4, 5, 6, 7, 8}; //{6, 3, 8, 5, 2, 7, 4, 1}; int i, j; int tmp; bool swapped; for (i = ARRSIZE - 1; i >= 0; i--){ swapped = false; for (j = 0; j < i; j++){ /* search from arr[0] to arr[i] */ if (arr[j] > arr[j + 1]){ /* if the element with lower index is larger swap the two elements */ tmp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tmp; swapped = true; } } if (!swapped) /* if did not swap anything then the array must be already sorted */ break; } printf("It took %d iteration%c to sort the array\n", ARRSIZE - i, (ARRSIZE - i) > 1 ? 's' : '\0'); /* print out the array */ for (i = 0; i < ARRSIZE; i++) printf(" %d", arr[i]); printf("\n"); return 0; }
the_stack_data/4610.c
int ft_atoi_base(const char *str, int str_base) { int i; int n; int len; int result; i = 0; n = 1; result = 0; if (str[i] == '-') { n = -1; i++; } while (str[i] != '\0') { result *= str_base; if (str[i] >= '0' && str[i] <= '9') result += str[i] - 48; else if (str[i] >= 'A' && str[i] <= 'Z') result += str[i] - 55; else if (str[i] >= 'a' && str[i] <= 'z') result += str[i] - 87; i++; } return (result * n); }
the_stack_data/513402.c
#define SIZE 101//AC 86ms 0.3S void putint(int out) { char buf[1000]; int n=0; if(out<0) putchar('-'),out=out*-1; do { buf[n++]='0'+(out%10); out=out/10; }while(out>0); for(n=n-1;n>=0;n--)putchar(buf[n]); putchar(' '); } int get_int(){ int n=0,si=1; char tc=getchar(); while((tc<'0'||tc>'9')&&tc!='-') tc=getchar(); if(tc=='-') tc=getchar(),si=-1; while(tc>='0'&&tc<='9') n=n*10+(tc-'0'),tc=getchar(); return n*si; } int main() { int n,data; int list[SIZE]={0}; n=get_int(); for(int i=0;i<n;++i){ data=get_int(); ++list[data]; } for(int i=1;i<101;++i){ for(int x=0;x<list[i];++x){ putint(i); } } }
the_stack_data/5598.c
/*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2000 The NetBSD Foundation, Inc. * All rights reserved. * * This code was contributed to The NetBSD Foundation by Allen Briggs. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $NetBSD: fmtcheck.c,v 1.8 2008/04/28 20:22:59 martin Exp $ * $FreeBSD: head/lib/libc/gen/fmtcheck.c 326193 2017-11-25 17:12:48Z pfg $ */ #include <stdio.h> #include <string.h> #include <ctype.h> const char *__fmtcheck(const char *, const char *); enum __e_fmtcheck_types { FMTCHECK_START, FMTCHECK_SHORT, FMTCHECK_INT, FMTCHECK_WINTT, FMTCHECK_LONG, FMTCHECK_QUAD, FMTCHECK_INTMAXT, FMTCHECK_PTRDIFFT, FMTCHECK_SIZET, FMTCHECK_CHARPOINTER, FMTCHECK_SHORTPOINTER, FMTCHECK_INTPOINTER, FMTCHECK_LONGPOINTER, FMTCHECK_QUADPOINTER, FMTCHECK_INTMAXTPOINTER, FMTCHECK_PTRDIFFTPOINTER, FMTCHECK_SIZETPOINTER, #ifndef NO_FLOATING_POINT FMTCHECK_DOUBLE, FMTCHECK_LONGDOUBLE, #endif FMTCHECK_STRING, FMTCHECK_WSTRING, FMTCHECK_WIDTH, FMTCHECK_PRECISION, FMTCHECK_DONE, FMTCHECK_UNKNOWN }; typedef enum __e_fmtcheck_types EFT; enum e_modifier { MOD_NONE, MOD_CHAR, MOD_SHORT, MOD_LONG, MOD_QUAD, MOD_INTMAXT, MOD_LONGDOUBLE, MOD_PTRDIFFT, MOD_SIZET, }; #define RETURN(pf,f,r) do { \ *(pf) = (f); \ return r; \ } /*NOTREACHED*/ /*CONSTCOND*/ while (0) static EFT get_next_format_from_precision(const char **pf) { enum e_modifier modifier; const char *f; f = *pf; switch (*f) { case 'h': f++; if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); if (*f == 'h') { f++; modifier = MOD_CHAR; } else { modifier = MOD_SHORT; } break; case 'j': f++; modifier = MOD_INTMAXT; break; case 'l': f++; if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); if (*f == 'l') { f++; modifier = MOD_QUAD; } else { modifier = MOD_LONG; } break; case 'q': f++; modifier = MOD_QUAD; break; case 't': f++; modifier = MOD_PTRDIFFT; break; case 'z': f++; modifier = MOD_SIZET; break; case 'L': f++; modifier = MOD_LONGDOUBLE; break; default: modifier = MOD_NONE; break; } if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); if (strchr("diouxX", *f)) { switch (modifier) { case MOD_LONG: RETURN(pf,f,FMTCHECK_LONG); case MOD_QUAD: RETURN(pf,f,FMTCHECK_QUAD); case MOD_INTMAXT: RETURN(pf,f,FMTCHECK_INTMAXT); case MOD_PTRDIFFT: RETURN(pf,f,FMTCHECK_PTRDIFFT); case MOD_SIZET: RETURN(pf,f,FMTCHECK_SIZET); case MOD_CHAR: case MOD_SHORT: case MOD_NONE: RETURN(pf,f,FMTCHECK_INT); default: RETURN(pf,f,FMTCHECK_UNKNOWN); } } if (*f == 'n') { switch (modifier) { case MOD_CHAR: RETURN(pf,f,FMTCHECK_CHARPOINTER); case MOD_SHORT: RETURN(pf,f,FMTCHECK_SHORTPOINTER); case MOD_LONG: RETURN(pf,f,FMTCHECK_LONGPOINTER); case MOD_QUAD: RETURN(pf,f,FMTCHECK_QUADPOINTER); case MOD_INTMAXT: RETURN(pf,f,FMTCHECK_INTMAXTPOINTER); case MOD_PTRDIFFT: RETURN(pf,f,FMTCHECK_PTRDIFFTPOINTER); case MOD_SIZET: RETURN(pf,f,FMTCHECK_SIZETPOINTER); case MOD_NONE: RETURN(pf,f,FMTCHECK_INTPOINTER); default: RETURN(pf,f,FMTCHECK_UNKNOWN); } } if (strchr("DOU", *f)) { if (modifier != MOD_NONE) RETURN(pf,f,FMTCHECK_UNKNOWN); RETURN(pf,f,FMTCHECK_LONG); } #ifndef NO_FLOATING_POINT if (strchr("aAeEfFgG", *f)) { switch (modifier) { case MOD_LONGDOUBLE: RETURN(pf,f,FMTCHECK_LONGDOUBLE); case MOD_LONG: case MOD_NONE: RETURN(pf,f,FMTCHECK_DOUBLE); default: RETURN(pf,f,FMTCHECK_UNKNOWN); } } #endif if (*f == 'c') { switch (modifier) { case MOD_LONG: RETURN(pf,f,FMTCHECK_WINTT); case MOD_NONE: RETURN(pf,f,FMTCHECK_INT); default: RETURN(pf,f,FMTCHECK_UNKNOWN); } } if (*f == 'C') { if (modifier != MOD_NONE) RETURN(pf,f,FMTCHECK_UNKNOWN); RETURN(pf,f,FMTCHECK_WINTT); } if (*f == 's') { switch (modifier) { case MOD_LONG: RETURN(pf,f,FMTCHECK_WSTRING); case MOD_NONE: RETURN(pf,f,FMTCHECK_STRING); default: RETURN(pf,f,FMTCHECK_UNKNOWN); } } if (*f == 'S') { if (modifier != MOD_NONE) RETURN(pf,f,FMTCHECK_UNKNOWN); RETURN(pf,f,FMTCHECK_WSTRING); } if (*f == 'p') { if (modifier != MOD_NONE) RETURN(pf,f,FMTCHECK_UNKNOWN); RETURN(pf,f,FMTCHECK_LONG); } RETURN(pf,f,FMTCHECK_UNKNOWN); /*NOTREACHED*/ } static EFT get_next_format_from_width(const char **pf) { const char *f; f = *pf; if (*f == '.') { f++; if (*f == '*') { RETURN(pf,f,FMTCHECK_PRECISION); } /* eat any precision (empty is allowed) */ while (isdigit(*f)) f++; if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); } RETURN(pf,f,get_next_format_from_precision(pf)); /*NOTREACHED*/ } static EFT get_next_format(const char **pf, EFT eft) { int infmt; const char *f; if (eft == FMTCHECK_WIDTH) { (*pf)++; return get_next_format_from_width(pf); } else if (eft == FMTCHECK_PRECISION) { (*pf)++; return get_next_format_from_precision(pf); } f = *pf; infmt = 0; while (!infmt) { f = strchr(f, '%'); if (f == NULL) RETURN(pf,f,FMTCHECK_DONE); f++; if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); if (*f != '%') infmt = 1; else f++; } /* Eat any of the flags */ while (*f && (strchr("#'0- +", *f))) f++; if (*f == '*') { RETURN(pf,f,FMTCHECK_WIDTH); } /* eat any width */ while (isdigit(*f)) f++; if (!*f) { RETURN(pf,f,FMTCHECK_UNKNOWN); } RETURN(pf,f,get_next_format_from_width(pf)); /*NOTREACHED*/ } const char * __fmtcheck(const char *f1, const char *f2) { const char *f1p, *f2p; EFT f1t, f2t; if (!f1) return f2; f1p = f1; f1t = FMTCHECK_START; f2p = f2; f2t = FMTCHECK_START; while ((f1t = get_next_format(&f1p, f1t)) != FMTCHECK_DONE) { if (f1t == FMTCHECK_UNKNOWN) return f2; f2t = get_next_format(&f2p, f2t); if (f1t != f2t) return f2; } return f1; } __weak_reference(__fmtcheck, fmtcheck);
the_stack_data/72013744.c
/* Tutorial week 1 example Name: Robert Eviston Date: 30/01/2014 */ #include <stdio.h> void sum(int, int); void product(int, int); main() { int num1 = 0; int num2 = 0; printf("Enter two numbers\n"); scanf("%d", &num1); scanf("%d", &num2); flushall(); // Call function sum sum(num1, num2); // product(num1, num2); getchar(); } // end main() // Implement function sum() void sum(int number1, int number2) { int total = 0; total = number1 + number2; printf("Sum is %d\n", total); number1++; number2++; product(number1, number2); } // end sum () void product(int var1, int var2) { int mult = 0; mult = var1 * var2; printf("Product is %d, when 1 added to both", mult); } // end product ()
the_stack_data/118179.c
/** * @file * @brief List directory contents. * * @date 02.07.09 * @author Anton Bondarev * @author Anton Kozlov * -- rewritten to use opendir */ #include <errno.h> #include <unistd.h> #include <string.h> #include <time.h> #include <stdio.h> #include <dirent.h> #include <pwd.h> #include <grp.h> #include <sys/stat.h> #include <limits.h> typedef void item_print(const char *path, struct stat *sb); static void print_usage(void) { printf("Usage: ls [-hlR] path\n"); } static void print_access(int flags) { putchar(flags & S_IROTH ? 'r' : '-'); putchar(flags & S_IWOTH ? 'w' : '-'); putchar(flags & S_IXOTH ? 'x' : '-'); } #define BUFLEN 1024 static void printer_simple(const char *path, struct stat *sb) { printf(" %s\n", path); } static void printer_long(const char *path, struct stat *sb) { struct passwd pwd, *res; struct group grp, *gres; char buf[BUFLEN]; char type; switch (sb->st_mode & S_IFMT) { case S_IFDIR: type = 'd'; break; case S_IFBLK: type = 'b'; break; case S_IFCHR: type = 'c'; break; case S_IFIFO: type = 'p'; break; case S_IFSOCK: type = 's'; break; default: type = '-'; break; } putchar(type); print_access(sb->st_mode >> 6); print_access(sb->st_mode >> 3); print_access(sb->st_mode); getpwuid_r(sb->st_uid, &pwd, buf, BUFLEN, &res); if (NULL == res) { printf(" %10d", sb->st_uid); } else { printf(" %10s", res->pw_name); } getgrgid_r(sb->st_gid, &grp, buf, BUFLEN, &gres); if (NULL == res) { printf(" %10d", sb->st_uid); } else { printf(" %10s", gres->gr_name); } printf(" %10d", (int)(sb->st_size)); printer_simple(path, sb); } static void print(char *path, DIR *dir, int recursive, item_print *printer) { struct dirent *dent; while (NULL != (dent = readdir(dir))) { int pathlen = strlen(path); int dent_namel = strlen(dent->d_name); char line[pathlen + dent_namel + 3]; struct stat sb; if (pathlen > 0) { sprintf(line, "%s/%s", path, dent->d_name); } else { strcpy(line, dent->d_name); } if (-1 == stat(line, &sb)) { printf("Cannot stat %s\n", line); continue; } printer(line, &sb); if (sb.st_mode & S_IFDIR && recursive) { DIR *d; if (NULL == (d = opendir(line))) { printf("Cannot recurse to %s\n", line); } print(line, d, recursive, printer); closedir(d); } } } int main(int argc, char **argv) { DIR *dir; int opt; char dir_name[NAME_MAX]; int recursive; item_print *printer; printer = printer_simple; recursive = 0; while (-1 != (opt = getopt(argc, argv, "Rlh"))) { switch(opt) { case 'h': print_usage(); return 0; case 'l': printer = printer_long; break; case 'R': recursive = 1; break; case '?': break; default: printf("ls: invalid option -- '%c'\n", optopt); return -EINVAL; } } if (optind < argc) { struct stat sb; if (-1 == stat(argv[optind], &sb)) { return -errno; } if (~sb.st_mode & S_IFDIR) { printer(argv[optind], &sb); return 0; } sprintf(dir_name, "%s", argv[optind]); } else { sprintf(dir_name, "%s", ""); } if (NULL == (dir = opendir(dir_name))) { return -errno; } print(dir_name, dir, recursive, printer); closedir(dir); return 0; }
the_stack_data/470366.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int main() { long int decimal = 0; int base, temp; char* init = malloc(100); scanf("%s", init); scanf("%d", &base); int len = (int)(strlen(init)) - 1; for (int i = 0; init[i] != '\0'; i++) { if(init[i] >= '0' && init[i] <= '9') { temp = init[i] - 48; } else if(init[i] >= 'A' && init[i] <= 'F') { temp = init[i] - 55; } decimal += (temp) * pow(base, len--); } long int quotient = decimal; int converted[100], j, i = 1; while (quotient != 0) { converted[i++] = quotient % 2; quotient = quotient / 2; } for (j = i - 1; j > 0; j--) printf("%d", converted[j]); return 0; }
the_stack_data/159516325.c
#include "unistd.h" char **environ;
the_stack_data/242331427.c
#include <stdio.h> #define MAX 3 void dump(float arr[MAX][MAX + 1]) { printf("__\t\t\t\t\t\t\t__\n"); for (int i = 0; i < MAX; i++) { printf("| "); for (int j = 0; j <= MAX; j++) printf("%s%7.3f ", (j == MAX) ? "| " : "", arr[i][j]); printf("|\n"); } printf("--\t\t\t\t\t\t\t--\n"); } int main() { float matrix[MAX][MAX + 1], x[MAX]; printf("\nEnter the elements of augmented matrix:\n\n"); for (int i = 0; i < MAX; i++) { printf(" Enter the entire row %d: ", i + 1); for (int j = 0; j <= MAX; j++) scanf("%f", &matrix[i][j]); } printf("\n\n Your matrix: \n"); dump(matrix); for (int j = 0; j < MAX; j++) for (int i = 0; i < MAX; i++) if (i > j) { float temp = matrix[i][j] / matrix[j][j]; for (int k = 0; k <= MAX; k++) matrix[i][k] = matrix[i][k] - temp * matrix[j][k]; } x[MAX - 1] = matrix[MAX - 1][MAX] / matrix[MAX - 1][MAX - 1]; for (int i = MAX - 2; i >= 0; i--) { float sum = 0; for (int j = i + 1; j < MAX; j++) sum += matrix[i][j] * x[j]; x[i] = (matrix[i][MAX] - sum) / matrix[i][i]; } printf("\n Solved matrix:\n"); dump(matrix); printf("\n The solution is: \n"); for (int i = 0; i < MAX; i++) printf(" %c = \t%.3f\n", i + 120, x[i]); return 0; }
the_stack_data/36006.c
/* * Requires a Unity build. Otherwise hidden_func is not specified. */ int main(void) { return hidden_func(); }
the_stack_data/99844.c
/** ****************************************************************************** * @file startup_stm32f4xx.s * @author Coocox * @version V1.0 * @date 03/05/2012 * @brief STM32F4xx Devices vector table for RIDE7 toolchain. * This module performs: * - Set the initial SP * - Set the initial PC == Reset_Handler, * - Set the vector table entries with the exceptions ISR address * - Configure the clock system and the external SRAM mounted on * STM324xG-EVAL board to be used as data memory (optional, * to be enabled by user) * - Branches to main in the C library (which eventually * calls main()). * After Reset the Cortex-M4 processor is in Thread mode, * priority is Privileged, and the Stack is set to Main. ****************************************************************************** */ /*----------Stack Configuration-----------------------------------------------*/ #define STACK_SIZE 0x00002000 /*!< The Stack size suggest using even number */ __attribute__ ((section(".co_stack"))) unsigned long pulStack[STACK_SIZE]; /*----------Macro definition--------------------------------------------------*/ #define WEAK __attribute__ ((weak)) /*----------Declaration of the default fault handlers-------------------------*/ /* System exception vector handler */ __attribute__ ((used)) void WEAK Reset_Handler(void); void WEAK NMI_Handler(void); void WEAK HardFault_Handler(void); void WEAK MemManage_Handler(void); void WEAK BusFault_Handler(void); void WEAK UsageFault_Handler(void); void WEAK SVC_Handler(void); void WEAK DebugMon_Handler(void); void WEAK PendSV_Handler(void); void WEAK SysTick_Handler(void); void WEAK WWDG_IRQHandler(void); void WEAK PVD_IRQHandler(void); void WEAK TAMP_STAMP_IRQHandler(void); void WEAK RTC_WKUP_IRQHandler(void); void WEAK FLASH_IRQHandler(void); void WEAK RCC_IRQHandler(void); void WEAK EXTI0_IRQHandler(void); void WEAK EXTI1_IRQHandler(void); void WEAK EXTI2_IRQHandler(void); void WEAK EXTI3_IRQHandler(void); void WEAK EXTI4_IRQHandler(void); void WEAK DMA1_Stream0_IRQHandler(void); void WEAK DMA1_Stream1_IRQHandler(void); void WEAK DMA1_Stream2_IRQHandler(void); void WEAK DMA1_Stream3_IRQHandler(void); void WEAK DMA1_Stream4_IRQHandler(void); void WEAK DMA1_Stream5_IRQHandler(void); void WEAK DMA1_Stream6_IRQHandler(void); void WEAK ADC_IRQHandler(void); void WEAK CAN1_TX_IRQHandler(void); void WEAK CAN1_RX0_IRQHandler(void); void WEAK CAN1_RX1_IRQHandler(void); void WEAK CAN1_SCE_IRQHandler(void); void WEAK EXTI9_5_IRQHandler(void); void WEAK TIM1_BRK_TIM9_IRQHandler(void); void WEAK TIM1_UP_TIM10_IRQHandler(void); void WEAK TIM1_TRG_COM_TIM11_IRQHandler(void); void WEAK TIM1_CC_IRQHandler(void); void WEAK TIM2_IRQHandler(void); void WEAK TIM3_IRQHandler(void); void WEAK TIM4_IRQHandler(void); void WEAK I2C1_EV_IRQHandler(void); void WEAK I2C1_ER_IRQHandler(void); void WEAK I2C2_EV_IRQHandler(void); void WEAK I2C2_ER_IRQHandler(void); void WEAK SPI1_IRQHandler(void); void WEAK SPI2_IRQHandler(void); void WEAK USART1_IRQHandler(void); void WEAK USART2_IRQHandler(void); void WEAK USART3_IRQHandler(void); void WEAK EXTI15_10_IRQHandler(void); void WEAK RTC_Alarm_IRQHandler(void); void WEAK OTG_FS_WKUP_IRQHandler(void); void WEAK TIM8_BRK_TIM12_IRQHandler(void); void WEAK TIM8_UP_TIM13_IRQHandler(void); void WEAK TIM8_TRG_COM_TIM14_IRQHandler(void); void WEAK TIM8_CC_IRQHandler(void); void WEAK DMA1_Stream7_IRQHandler(void); void WEAK FSMC_IRQHandler(void); void WEAK SDIO_IRQHandler(void); void WEAK TIM5_IRQHandler(void); void WEAK SPI3_IRQHandler(void); void WEAK UART4_IRQHandler(void); void WEAK UART5_IRQHandler(void); void WEAK TIM6_DAC_IRQHandler(void); void WEAK TIM7_IRQHandler(void); void WEAK DMA2_Stream0_IRQHandler(void); void WEAK DMA2_Stream1_IRQHandler(void); void WEAK DMA2_Stream2_IRQHandler(void); void WEAK DMA2_Stream3_IRQHandler(void); void WEAK DMA2_Stream4_IRQHandler(void); void WEAK ETH_IRQHandler(void); void WEAK ETH_WKUP_IRQHandler(void); void WEAK CAN2_TX_IRQHandler(void); void WEAK CAN2_RX0_IRQHandler(void); void WEAK CAN2_RX1_IRQHandler(void); void WEAK CAN2_SCE_IRQHandler(void); void WEAK OTG_FS_IRQHandler(void); void WEAK DMA2_Stream5_IRQHandler(void); void WEAK DMA2_Stream6_IRQHandler(void); void WEAK DMA2_Stream7_IRQHandler(void); void WEAK USART6_IRQHandler(void); void WEAK I2C3_EV_IRQHandler(void); void WEAK I2C3_ER_IRQHandler(void); void WEAK OTG_HS_EP1_OUT_IRQHandler(void); void WEAK OTG_HS_EP1_IN_IRQHandler(void); void WEAK OTG_HS_WKUP_IRQHandler(void); void WEAK OTG_HS_IRQHandler(void); void WEAK DCMI_IRQHandler(void); void WEAK CRYP_IRQHandler(void); void WEAK HASH_RNG_IRQHandler(void); void WEAK FPU_IRQHandler(void); /*----------Symbols defined in linker script----------------------------------*/ extern unsigned long _sidata; /*!< Start address for the initialization values of the .data section. */ extern unsigned long _sdata; /*!< Start address for the .data section */ extern unsigned long _edata; /*!< End address for the .data section */ extern unsigned long _sbss; /*!< Start address for the .bss section */ extern unsigned long _ebss; /*!< End address for the .bss section */ extern void _eram; /*!< End address for ram */ /*----------Function prototypes-----------------------------------------------*/ extern int main(void); /*!< The entry point for the application. */ //extern void SystemInit(void); /*!< Setup the microcontroller system(CMSIS) */ void Default_Reset_Handler(void); /*!< Default reset handler */ static void Default_Handler(void); /*!< Default exception handler */ /** *@brief The minimal vector table for a Cortex M3. Note that the proper constructs * must be placed on this to ensure that it ends up at physical address * 0x00000000. */ __attribute__ ((used,section(".isr_vector"))) void (* const g_pfnVectors[])(void) = { /*----------Core Exceptions------------------------------------------------ */ (void *)&pulStack[STACK_SIZE], /*!< The initial stack pointer */ Reset_Handler, /*!< Reset Handler */ NMI_Handler, /*!< NMI Handler */ HardFault_Handler, /*!< Hard Fault Handler */ MemManage_Handler, /*!< MPU Fault Handler */ BusFault_Handler, /*!< Bus Fault Handler */ UsageFault_Handler, /*!< Usage Fault Handler */ 0,0,0,0, /*!< Reserved */ SVC_Handler, /*!< SVCall Handler */ DebugMon_Handler, /*!< Debug Monitor Handler */ 0, /*!< Reserved */ PendSV_Handler, /*!< PendSV Handler */ SysTick_Handler, /*!< SysTick Handler */ /*----------External Exceptions---------------------------------------------*/ WWDG_IRQHandler, /*!< 0: Window WatchDog */ PVD_IRQHandler, /*!< 1: PVD through EXTI Line detection */ TAMP_STAMP_IRQHandler, /*!< 2: Tamper and TimeStamps through the EXTI line*/ RTC_WKUP_IRQHandler, /*!< 3: RTC Wakeup through the EXTI line */ FLASH_IRQHandler, /*!< 4: FLASH */ RCC_IRQHandler , /*!< 5: RCC */ EXTI0_IRQHandler, /*!< 6: EXTI Line0 */ EXTI1_IRQHandler, /*!< 7: EXTI Line1 */ EXTI2_IRQHandler, /*!< 8: EXTI Line2 */ EXTI3_IRQHandler, /*!< 9: EXTI Line3 */ EXTI4_IRQHandler, /*!< 10: EXTI Line4 */ DMA1_Stream0_IRQHandler, /*!< 11: DMA1 Stream 0 */ DMA1_Stream1_IRQHandler, /*!< 12: DMA1 Stream 1 */ DMA1_Stream2_IRQHandler, /*!< 13: DMA1 Stream 2 */ DMA1_Stream3_IRQHandler, /*!< 14: DMA1 Stream 3 */ DMA1_Stream4_IRQHandler, /*!< 15: DMA1 Stream 4 */ DMA1_Stream5_IRQHandler, /*!< 16: DMA1 Stream 5 */ DMA1_Stream6_IRQHandler, /*!< 17: DMA1 Stream 6 */ ADC_IRQHandler, /*!< 18: ADC1, ADC2 and ADC3s */ CAN1_TX_IRQHandler, /*!< 19: CAN1 TX */ CAN1_RX0_IRQHandler, /*!< 20: CAN1 RX0 */ CAN1_RX1_IRQHandler, /*!< 21: CAN1 RX1 */ CAN1_SCE_IRQHandler, /*!< 22: CAN1 SCE */ EXTI9_5_IRQHandler, /*!< 23: External Line[9:5]s */ TIM1_BRK_TIM9_IRQHandler, /*!< 24: TIM1 Break and TIM9 */ TIM1_UP_TIM10_IRQHandler, /*!< 25: TIM1 Update and TIM10 */ TIM1_TRG_COM_TIM11_IRQHandler,/*!< 26: TIM1 Trigger and Commutation and TIM11*/ TIM1_CC_IRQHandler, /*!< 27: TIM1 Capture Compare */ TIM2_IRQHandler, /*!< 28: TIM2 */ TIM3_IRQHandler, /*!< 29: TIM3 */ TIM4_IRQHandler, /*!< 30: TIM4 */ I2C1_EV_IRQHandler, /*!< 31: I2C1 Event */ I2C1_ER_IRQHandler, /*!< 32: I2C1 Error */ I2C2_EV_IRQHandler, /*!< 33: I2C2 Event */ I2C2_ER_IRQHandler, /*!< 34: I2C2 Error */ SPI1_IRQHandler, /*!< 35: SPI1 */ SPI2_IRQHandler, /*!< 36: SPI2 */ USART1_IRQHandler, /*!< 37: USART1 */ USART2_IRQHandler, /*!< 38: USART2 */ USART3_IRQHandler, /*!< 39: USART3 */ EXTI15_10_IRQHandler, /*!< 40: External Line[15:10]s */ RTC_Alarm_IRQHandler, /*!< 41: RTC Alarm (A and B) through EXTI Line */ OTG_FS_WKUP_IRQHandler, /*!< 42: USB OTG FS Wakeup through EXTI line */ TIM8_BRK_TIM12_IRQHandler, /*!< 43: TIM8 Break and TIM12 */ TIM8_UP_TIM13_IRQHandler, /*!< 44: TIM8 Update and TIM13 */ TIM8_TRG_COM_TIM14_IRQHandler,/*!< 45:TIM8 Trigger and Commutation and TIM14*/ TIM8_CC_IRQHandler, /*!< 46: TIM8 Capture Compare */ DMA1_Stream7_IRQHandler, /*!< 47: DMA1 Stream7 */ FSMC_IRQHandler, /*!< 48: FSMC */ SDIO_IRQHandler, /*!< 49: SDIO */ TIM5_IRQHandler, /*!< 50: TIM5 */ SPI3_IRQHandler, /*!< 51: SPI3 */ UART4_IRQHandler, /*!< 52: UART4 */ UART5_IRQHandler, /*!< 53: UART5 */ TIM6_DAC_IRQHandler, /*!< 54: TIM6 and DAC1&2 underrun errors */ TIM7_IRQHandler, /*!< 55: TIM7 */ DMA2_Stream0_IRQHandler, /*!< 56: DMA2 Stream 0 */ DMA2_Stream1_IRQHandler, /*!< 57: DMA2 Stream 1 */ DMA2_Stream2_IRQHandler, /*!< 58: DMA2 Stream 2 */ DMA2_Stream3_IRQHandler, /*!< 59: DMA2 Stream 3 */ DMA2_Stream4_IRQHandler, /*!< 60: DMA2 Stream 4 */ ETH_IRQHandler, /*!< 61: Ethernet */ ETH_WKUP_IRQHandler, /*!< 62: Ethernet Wakeup through EXTI line */ CAN2_TX_IRQHandler, /*!< 63: CAN2 TX */ CAN2_RX0_IRQHandler, /*!< 64: CAN2 RX0 */ CAN2_RX1_IRQHandler, /*!< 65: CAN2 RX1 */ CAN2_SCE_IRQHandler, /*!< 66: CAN2 SCE */ OTG_FS_IRQHandler, /*!< 67: USB OTG FS */ DMA2_Stream5_IRQHandler, /*!< 68: DMA2 Stream 5 */ DMA2_Stream6_IRQHandler, /*!< 69: DMA2 Stream 6 */ DMA2_Stream7_IRQHandler, /*!< 70: DMA2 Stream 7 */ USART6_IRQHandler, /*!< 71: USART6 */ I2C3_EV_IRQHandler, /*!< 72: I2C3 event */ I2C3_ER_IRQHandler, /*!< 73: I2C3 error */ OTG_HS_EP1_OUT_IRQHandler, /*!< 74: USB OTG HS End Point 1 Out */ OTG_HS_EP1_IN_IRQHandler, /*!< 75: USB OTG HS End Point 1 In */ OTG_HS_WKUP_IRQHandler, /*!< 76: USB OTG HS Wakeup through EXTI */ OTG_HS_IRQHandler, /*!< 77: USB OTG HS */ DCMI_IRQHandler, /*!< 53: DCMI */ CRYP_IRQHandler, /*!< 53: CRYP crypto */ HASH_RNG_IRQHandler, /*!< 53: Hash and Rng */ FPU_IRQHandler /*!< 53: FPU */ }; /** * @brief This is the code that gets called when the processor first * starts execution following a reset event. Only the absolutely * necessary set is performed, after which the application * supplied main() routine is called. * @param None * @retval None */ void Default_Reset_Handler(void) { /* Initialize data and bss */ unsigned long *pulSrc, *pulDest; /* Copy the data segment initializers from flash to SRAM */ pulSrc = &_sidata; for(pulDest = &_sdata; pulDest < &_edata; ) { *(pulDest++) = *(pulSrc++); } /* Zero fill the bss segment. This is done with inline assembly since this will clear the value of pulDest if it is not kept in a register. */ __asm(" ldr r0, =_sbss\n" " ldr r1, =_ebss\n" " mov r2, #0\n" " .thumb_func\n" "zero_loop:\n" " cmp r0, r1\n" " it lt\n" " strlt r2, [r0], #4\n" " blt zero_loop"); #ifdef __FPU_USED /* Enable FPU.*/ __asm(" LDR.W R0, =0xE000ED88\n" " LDR R1, [R0]\n" " ORR R1, R1, #(0xF << 20)\n" " STR R1, [R0]"); #endif /* Call the application's entry point.*/ main(); } /** *@brief Provide weak aliases for each Exception handler to the Default_Handler. * As they are weak aliases, any function with the same name will override * this definition. */ #pragma weak Reset_Handler = Default_Reset_Handler #pragma weak NMI_Handler = Default_Handler #pragma weak HardFault_Handler = Default_Handler #pragma weak MemManage_Handler = Default_Handler #pragma weak BusFault_Handler = Default_Handler #pragma weak UsageFault_Handler = Default_Handler #pragma weak SVC_Handler = Default_Handler #pragma weak DebugMon_Handler = Default_Handler #pragma weak PendSV_Handler = Default_Handler #pragma weak SysTick_Handler = Default_Handler #pragma weak WWDG_IRQHandler = Default_Handler #pragma weak PVD_IRQHandler = Default_Handler #pragma weak TAMP_STAMP_IRQHandler = Default_Handler #pragma weak RTC_WKUP_IRQHandler = Default_Handler #pragma weak FLASH_IRQHandler = Default_Handler #pragma weak RCC_IRQHandler = Default_Handler #pragma weak EXTI0_IRQHandler = Default_Handler #pragma weak EXTI1_IRQHandler = Default_Handler #pragma weak EXTI2_IRQHandler = Default_Handler #pragma weak EXTI3_IRQHandler = Default_Handler #pragma weak EXTI4_IRQHandler = Default_Handler #pragma weak DMA1_Stream0_IRQHandler = Default_Handler #pragma weak DMA1_Stream1_IRQHandler = Default_Handler #pragma weak DMA1_Stream2_IRQHandler = Default_Handler #pragma weak DMA1_Stream3_IRQHandler = Default_Handler #pragma weak DMA1_Stream4_IRQHandler = Default_Handler #pragma weak DMA1_Stream5_IRQHandler = Default_Handler #pragma weak DMA1_Stream6_IRQHandler = Default_Handler #pragma weak ADC_IRQHandler = Default_Handler #pragma weak CAN1_TX_IRQHandler = Default_Handler #pragma weak CAN1_RX0_IRQHandler = Default_Handler #pragma weak CAN1_RX1_IRQHandler = Default_Handler #pragma weak CAN1_SCE_IRQHandler = Default_Handler #pragma weak EXTI9_5_IRQHandler = Default_Handler #pragma weak TIM1_BRK_TIM9_IRQHandler = Default_Handler #pragma weak TIM1_UP_TIM10_IRQHandler = Default_Handler #pragma weak TIM1_TRG_COM_TIM11_IRQHandler = Default_Handler #pragma weak TIM1_CC_IRQHandler = Default_Handler #pragma weak TIM2_IRQHandler = Default_Handler #pragma weak TIM3_IRQHandler = Default_Handler #pragma weak TIM4_IRQHandler = Default_Handler #pragma weak I2C1_EV_IRQHandler = Default_Handler #pragma weak I2C1_ER_IRQHandler = Default_Handler #pragma weak I2C2_EV_IRQHandler = Default_Handler #pragma weak I2C2_ER_IRQHandler = Default_Handler #pragma weak SPI1_IRQHandler = Default_Handler #pragma weak SPI2_IRQHandler = Default_Handler #pragma weak USART1_IRQHandler = Default_Handler #pragma weak USART2_IRQHandler = Default_Handler #pragma weak USART3_IRQHandler = Default_Handler #pragma weak EXTI15_10_IRQHandler = Default_Handler #pragma weak RTC_Alarm_IRQHandler = Default_Handler #pragma weak OTG_FS_WKUP_IRQHandler = Default_Handler #pragma weak TIM8_BRK_TIM12_IRQHandler = Default_Handler #pragma weak TIM8_UP_TIM13_IRQHandler = Default_Handler #pragma weak TIM8_TRG_COM_TIM14_IRQHandler = Default_Handler #pragma weak TIM8_CC_IRQHandler = Default_Handler #pragma weak DMA1_Stream7_IRQHandler = Default_Handler #pragma weak FSMC_IRQHandler = Default_Handler #pragma weak SDIO_IRQHandler = Default_Handler #pragma weak TIM5_IRQHandler = Default_Handler #pragma weak SPI3_IRQHandler = Default_Handler #pragma weak UART4_IRQHandler = Default_Handler #pragma weak UART5_IRQHandler = Default_Handler #pragma weak TIM6_DAC_IRQHandler = Default_Handler #pragma weak TIM7_IRQHandler = Default_Handler #pragma weak DMA2_Stream0_IRQHandler = Default_Handler #pragma weak DMA2_Stream1_IRQHandler = Default_Handler #pragma weak DMA2_Stream2_IRQHandler = Default_Handler #pragma weak DMA2_Stream3_IRQHandler = Default_Handler #pragma weak DMA2_Stream4_IRQHandler = Default_Handler #pragma weak ETH_IRQHandler = Default_Handler #pragma weak ETH_WKUP_IRQHandler = Default_Handler #pragma weak CAN2_TX_IRQHandler = Default_Handler #pragma weak CAN2_RX0_IRQHandler = Default_Handler #pragma weak CAN2_RX1_IRQHandler = Default_Handler #pragma weak CAN2_SCE_IRQHandler = Default_Handler #pragma weak OTG_FS_IRQHandler = Default_Handler #pragma weak DMA2_Stream5_IRQHandler = Default_Handler #pragma weak DMA2_Stream6_IRQHandler = Default_Handler #pragma weak DMA2_Stream7_IRQHandler = Default_Handler #pragma weak USART6_IRQHandler = Default_Handler #pragma weak I2C3_EV_IRQHandler = Default_Handler #pragma weak I2C3_ER_IRQHandler = Default_Handler #pragma weak OTG_HS_EP1_OUT_IRQHandler = Default_Handler #pragma weak OTG_HS_EP1_IN_IRQHandler = Default_Handler #pragma weak OTG_HS_WKUP_IRQHandler = Default_Handler #pragma weak OTG_HS_IRQHandler = Default_Handler #pragma weak DCMI_IRQHandler = Default_Handler #pragma weak CRYP_IRQHandler = Default_Handler #pragma weak HASH_RNG_IRQHandler = Default_Handler #pragma weak FPU_IRQHandler = Default_Handler /** * @brief This is the code that gets called when the processor receives an * unexpected interrupt. This simply enters an infinite loop, * preserving the system state for examination by a debugger. * @param None * @retval None */ static void Default_Handler(void) { /* Go into an infinite loop. */ while (1) { } } /*********************** (C) COPYRIGHT 2009 Coocox ************END OF FILE*****/
the_stack_data/11740.c
#include <stdio.h> #include <string.h> int main() { char string[10]; int A = -73; unsigned int B = 31337; strcpy(string, "sample"); // Example of printing with different format string printf("[A] Dec: %d, Hex: %x, Unsigned: %u\n", A, A, A); printf("[B] Dec: %d, Hex: %x, Unsigned: %u\n", B, B, B); printf("[field width on B] 3: '%3u', 10: '%10u', '%08u'\n", B, B, B); printf("[string] %s Address %p\n", string, (void*)string); // Example of unary address operator (dereferencing) and a %x format string printf("variable A is at address: %p\n", (void*)&A); return 0; }
the_stack_data/140765204.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* maths.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kibotrel <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/06/14 16:08:51 by kibotrel #+# #+# */ /* Updated: 2019/06/27 15:44:22 by kibotrel ### ########.fr */ /* */ /* ************************************************************************** */ #include <stdlib.h> int big_endian4(unsigned char *nb) { return ((nb[0] << 24) | (nb[1] << 16) | (nb[2] << 8) | (nb[3])); } int big_endian2(unsigned char *nb) { return ((nb[0] << 8) | (nb[1])); } int is_power_two(int nb) { return ((nb == 1 || nb == 2 || nb == 4 || nb == 8 || nb == 16 ? 1 : 0)); } unsigned int create_pixel(unsigned char *raw, int bpp, int pos) { int i; int shift; unsigned int pixel; i = -1; shift = bpp - 1; pixel = 0; while (++i < bpp) pixel |= (raw[pos++] << (8 * shift--)); return (pixel); } unsigned char predict(unsigned char a, unsigned char b, unsigned char c) { unsigned char p; unsigned char pa; unsigned char pb; unsigned char pc; p = a + b - c; pa = abs(p - a); pb = abs(p - b); pc = abs(p - c); if (pa <= pb && pa <= pc) return (a); else if (pb <= pc) return (b); return (c); }
the_stack_data/1246945.c
/*------------------------------------------------------------------------- _divuint.c - routine for unsigned int (16 bit) division Copyright (C) 1999, Jean-Louis Vern <jlvern AT gmail.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, if you link this library with other files, some of which are compiled with SDCC, to produce an executable, this library does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. -------------------------------------------------------------------------*/ /* Assembler-functions are provided for: mcs51 small mcs51 small stack-auto */ #if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) # if defined(__SDCC_mcs51) # if defined(__SDCC_MODEL_SMALL) # if defined(__SDCC_STACK_AUTO) # define _DIVUINT_ASM_SMALL_AUTO # else # define _DIVUINT_ASM_SMALL # endif # endif # endif #endif #if defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO static void _divuint_dummy (void) _naked { __asm .globl __divuint __divuint: #define count r2 #define reste_l r3 #define reste_h r4 #define al dpl #define ah dph #if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) ar0 = 0 ; BUG register set is not considered ar1 = 1 .globl __divint mov a,sp add a,#-2 ; 2 bytes return address mov r0,a ; r0 points to bh mov ar1,@r0 ; load bh dec r0 mov ar0,@r0 ; load bl #define bl r0 #define bh r1 __divint: ; entry point for __divsint #else // __SDCC_STACK_AUTO #if !defined(__SDCC_PARMS_IN_BANK1) #if defined(__SDCC_NOOVERLAY) .area DSEG (DATA) #else .area OSEG (OVR,DATA) #endif .globl __divuint_PARM_2 .globl __divsint_PARM_2 __divuint_PARM_2: __divsint_PARM_2: .ds 2 .area CSEG (CODE) #endif // !__SDCC_PARMS_IN_BANK1 #if defined(__SDCC_PARMS_IN_BANK1) #define bl (b1_0) #define bh (b1_1) #else #define bl (__divuint_PARM_2) #define bh (__divuint_PARM_2 + 1) #endif // __SDCC_PARMS_IN_BANK1 #endif // __SDCC_STACK_AUTO mov count,#16 clr a mov reste_l,a mov reste_h,a loop: mov a,al ; a <<= 1 add a,acc mov al,a mov a,ah rlc a mov ah,a mov a,reste_l ; reste <<= 1 rlc a ; feed in carry mov reste_l,a mov a,reste_h rlc a mov reste_h,a mov a,reste_l ; reste - b subb a,bl ; here carry is always clear, because ; reste <<= 1 never overflows mov b,a mov a,reste_h subb a,bh jc smaller ; reste >= b? mov reste_h,a ; -> yes; reste = reste - b; mov reste_l,b orl al,#1 smaller: ; -> no djnz count,loop ret __endasm ; } #else // defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) unsigned int _divuint (unsigned int a, unsigned int b) { unsigned int reste = 0; unsigned char count = 16; char c; do { // reste: a <- 0; c = MSB_SET(a); a <<= 1; reste <<= 1; if (c) reste |= 1; if (reste >= b) { reste -= b; // a <- (result = 1) a |= 1; } } while (--count); return a; } #endif // defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO
the_stack_data/120773.c
#include <stdio.h> struct ListNode { int val; struct ListNode *next; }; struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) { if ( !headA || !headB ) return NULL; struct ListNode *p1, *p2; struct ListNode *tailA = headA, *tailB = headB; while ( (*tailA).next != NULL ) tailA = (*tailA).next; while ( (*tailB).next != NULL ) tailB = (*tailB).next; if ( tailA != tailB ) return NULL; (*tailA).next = headA; p1 = (*headB).next; p2 = (*p1).next; while ( p1 != p2 ) { p1 = (*p1).next; p2 = (*p2).next; p2 = (*p2).next; } p2 = headB; while ( p1 != p2 ) { p1 = (*p1).next; p2 = (*p2).next; } (*tailA).next = NULL; return p1; } int main() { return 0; }
the_stack_data/107035.c
/* $OpenBSD: strtoll.c,v 1.6 2005/11/10 10:00:17 espie Exp $ */ /*- * Copyright (c) 1992 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <sys/types.h> #include <ctype.h> #include <errno.h> #include <limits.h> #include <stdlib.h> /* * Convert a string to a long long. * * Ignores `locale' stuff. Assumes that the upper and lower case * alphabets and digits are each contiguous. */ long long strtoll(const char *nptr, char **endptr, int base) { const char *s; long long acc, cutoff; int c; int neg, any, cutlim; /* * Skip white space and pick up leading +/- sign if any. * If base is 0, allow 0x for hex and 0 for octal, else * assume decimal; if base is already 16, allow 0x. */ s = nptr; do { c = (unsigned char) *s++; } while (isspace(c)); if (c == '-') { neg = 1; c = *s++; } else { neg = 0; if (c == '+') c = *s++; } if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; s += 2; base = 16; } if (base == 0) base = c == '0' ? 8 : 10; /* * Compute the cutoff value between legal numbers and illegal * numbers. That is the largest legal value, divided by the * base. An input number that is greater than this value, if * followed by a legal input character, is too big. One that * is equal to this value may be valid or not; the limit * between valid and invalid numbers is then based on the last * digit. For instance, if the range for long longs is * [-9223372036854775808..9223372036854775807] and the input base * is 10, cutoff will be set to 922337203685477580 and cutlim to * either 7 (neg==0) or 8 (neg==1), meaning that if we have * accumulated a value > 922337203685477580, or equal but the * next digit is > 7 (or 8), the number is too big, and we will * return a range error. * * Set any if any `digits' consumed; make it negative to indicate * overflow. */ cutoff = neg ? LLONG_MIN : LLONG_MAX; cutlim = cutoff % base; cutoff /= base; if (neg) { if (cutlim > 0) { cutlim -= base; cutoff += 1; } cutlim = -cutlim; } for (acc = 0, any = 0;; c = (unsigned char) *s++) { if (isdigit(c)) c -= '0'; else if (isalpha(c)) c -= isupper(c) ? 'A' - 10 : 'a' - 10; else break; if (c >= base) break; if (any < 0) continue; if (neg) { if (acc < cutoff || (acc == cutoff && c > cutlim)) { any = -1; acc = LLONG_MIN; errno = ERANGE; } else { any = 1; acc *= base; acc -= c; } } else { if (acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; acc = LLONG_MAX; errno = ERANGE; } else { any = 1; acc *= base; acc += c; } } } if (endptr != 0) *endptr = (char *) (any ? s - 1 : nptr); return (acc); }
the_stack_data/31389038.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int expression) { if (!expression) { ERROR: __VERIFIER_error(); }; return; } int __global_lock; void __VERIFIER_atomic_begin() { __VERIFIER_assume(__global_lock==0); __global_lock=1; return; } void __VERIFIER_atomic_end() { __VERIFIER_assume(__global_lock==1); __global_lock=0; return; } #include <assert.h> #include <pthread.h> #ifndef TRUE #define TRUE (_Bool)1 #endif #ifndef FALSE #define FALSE (_Bool)0 #endif #ifndef NULL #define NULL ((void*)0) #endif #ifndef FENCE #define FENCE(x) ((void)0) #endif #ifndef IEEE_FLOAT_EQUAL #define IEEE_FLOAT_EQUAL(x,y) (x==y) #endif #ifndef IEEE_FLOAT_NOTEQUAL #define IEEE_FLOAT_NOTEQUAL(x,y) (x!=y) #endif void * P0(void *arg); void * P1(void *arg); void * P2(void *arg); void fence(); void isync(); void lwfence(); int __unbuffered_cnt; int __unbuffered_cnt = 0; int __unbuffered_p0_EAX; int __unbuffered_p0_EAX = 0; int __unbuffered_p0_EBX; int __unbuffered_p0_EBX = 0; int __unbuffered_p2_EAX; int __unbuffered_p2_EAX = 0; int __unbuffered_p2_EBX; int __unbuffered_p2_EBX = 0; int a; int a = 0; _Bool a$flush_delayed; int a$mem_tmp; _Bool a$r_buff0_thd0; _Bool a$r_buff0_thd1; _Bool a$r_buff0_thd2; _Bool a$r_buff0_thd3; _Bool a$r_buff1_thd0; _Bool a$r_buff1_thd1; _Bool a$r_buff1_thd2; _Bool a$r_buff1_thd3; _Bool a$read_delayed; int *a$read_delayed_var; int a$w_buff0; _Bool a$w_buff0_used; int a$w_buff1; _Bool a$w_buff1_used; _Bool main$tmp_guard0; _Bool main$tmp_guard1; int x; int x = 0; int y; int y = 0; int z; int z = 0; _Bool weak$$choice0; _Bool weak$$choice2; void * P0(void *arg) { __VERIFIER_atomic_begin(); a$w_buff1 = a$w_buff0; a$w_buff0 = 1; a$w_buff1_used = a$w_buff0_used; a$w_buff0_used = TRUE; __VERIFIER_assert(!(a$w_buff1_used && a$w_buff0_used)); a$r_buff1_thd0 = a$r_buff0_thd0; a$r_buff1_thd1 = a$r_buff0_thd1; a$r_buff1_thd2 = a$r_buff0_thd2; a$r_buff1_thd3 = a$r_buff0_thd3; a$r_buff0_thd1 = TRUE; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); x = 1; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __unbuffered_p0_EAX = x; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __unbuffered_p0_EBX = y; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); a = a$w_buff0_used && a$r_buff0_thd1 ? a$w_buff0 : (a$w_buff1_used && a$r_buff1_thd1 ? a$w_buff1 : a); a$w_buff0_used = a$w_buff0_used && a$r_buff0_thd1 ? FALSE : a$w_buff0_used; a$w_buff1_used = a$w_buff0_used && a$r_buff0_thd1 || a$w_buff1_used && a$r_buff1_thd1 ? FALSE : a$w_buff1_used; a$r_buff0_thd1 = a$w_buff0_used && a$r_buff0_thd1 ? FALSE : a$r_buff0_thd1; a$r_buff1_thd1 = a$w_buff0_used && a$r_buff0_thd1 || a$w_buff1_used && a$r_buff1_thd1 ? FALSE : a$r_buff1_thd1; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __unbuffered_cnt = __unbuffered_cnt + 1; __VERIFIER_atomic_end(); return nondet_0(); } void * P1(void *arg) { __VERIFIER_atomic_begin(); y = 1; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); z = 1; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); a = a$w_buff0_used && a$r_buff0_thd2 ? a$w_buff0 : (a$w_buff1_used && a$r_buff1_thd2 ? a$w_buff1 : a); a$w_buff0_used = a$w_buff0_used && a$r_buff0_thd2 ? FALSE : a$w_buff0_used; a$w_buff1_used = a$w_buff0_used && a$r_buff0_thd2 || a$w_buff1_used && a$r_buff1_thd2 ? FALSE : a$w_buff1_used; a$r_buff0_thd2 = a$w_buff0_used && a$r_buff0_thd2 ? FALSE : a$r_buff0_thd2; a$r_buff1_thd2 = a$w_buff0_used && a$r_buff0_thd2 || a$w_buff1_used && a$r_buff1_thd2 ? FALSE : a$r_buff1_thd2; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __unbuffered_cnt = __unbuffered_cnt + 1; __VERIFIER_atomic_end(); return nondet_0(); } void * P2(void *arg) { __VERIFIER_atomic_begin(); z = 2; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __unbuffered_p2_EAX = z; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); weak$$choice0 = nondet_1(); weak$$choice2 = nondet_1(); a$flush_delayed = weak$$choice2; a$mem_tmp = a; a = !a$w_buff0_used || !a$r_buff0_thd3 && !a$w_buff1_used || !a$r_buff0_thd3 && !a$r_buff1_thd3 ? a : (a$w_buff0_used && a$r_buff0_thd3 ? a$w_buff0 : a$w_buff1); a$w_buff0 = weak$$choice2 ? a$w_buff0 : (!a$w_buff0_used || !a$r_buff0_thd3 && !a$w_buff1_used || !a$r_buff0_thd3 && !a$r_buff1_thd3 ? a$w_buff0 : (a$w_buff0_used && a$r_buff0_thd3 ? a$w_buff0 : a$w_buff0)); a$w_buff1 = weak$$choice2 ? a$w_buff1 : (!a$w_buff0_used || !a$r_buff0_thd3 && !a$w_buff1_used || !a$r_buff0_thd3 && !a$r_buff1_thd3 ? a$w_buff1 : (a$w_buff0_used && a$r_buff0_thd3 ? a$w_buff1 : a$w_buff1)); a$w_buff0_used = weak$$choice2 ? a$w_buff0_used : (!a$w_buff0_used || !a$r_buff0_thd3 && !a$w_buff1_used || !a$r_buff0_thd3 && !a$r_buff1_thd3 ? a$w_buff0_used : (a$w_buff0_used && a$r_buff0_thd3 ? FALSE : a$w_buff0_used)); a$w_buff1_used = weak$$choice2 ? a$w_buff1_used : (!a$w_buff0_used || !a$r_buff0_thd3 && !a$w_buff1_used || !a$r_buff0_thd3 && !a$r_buff1_thd3 ? a$w_buff1_used : (a$w_buff0_used && a$r_buff0_thd3 ? FALSE : FALSE)); a$r_buff0_thd3 = weak$$choice2 ? a$r_buff0_thd3 : (!a$w_buff0_used || !a$r_buff0_thd3 && !a$w_buff1_used || !a$r_buff0_thd3 && !a$r_buff1_thd3 ? a$r_buff0_thd3 : (a$w_buff0_used && a$r_buff0_thd3 ? FALSE : a$r_buff0_thd3)); a$r_buff1_thd3 = weak$$choice2 ? a$r_buff1_thd3 : (!a$w_buff0_used || !a$r_buff0_thd3 && !a$w_buff1_used || !a$r_buff0_thd3 && !a$r_buff1_thd3 ? a$r_buff1_thd3 : (a$w_buff0_used && a$r_buff0_thd3 ? FALSE : FALSE)); __unbuffered_p2_EBX = a; a = a$flush_delayed ? a$mem_tmp : a; a$flush_delayed = FALSE; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); a = a$w_buff0_used && a$r_buff0_thd3 ? a$w_buff0 : (a$w_buff1_used && a$r_buff1_thd3 ? a$w_buff1 : a); a$w_buff0_used = a$w_buff0_used && a$r_buff0_thd3 ? FALSE : a$w_buff0_used; a$w_buff1_used = a$w_buff0_used && a$r_buff0_thd3 || a$w_buff1_used && a$r_buff1_thd3 ? FALSE : a$w_buff1_used; a$r_buff0_thd3 = a$w_buff0_used && a$r_buff0_thd3 ? FALSE : a$r_buff0_thd3; a$r_buff1_thd3 = a$w_buff0_used && a$r_buff0_thd3 || a$w_buff1_used && a$r_buff1_thd3 ? FALSE : a$r_buff1_thd3; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); __unbuffered_cnt = __unbuffered_cnt + 1; __VERIFIER_atomic_end(); return nondet_0(); } void fence() { } void isync() { } void lwfence() { } int main() { pthread_create(NULL, NULL, P0, NULL); pthread_create(NULL, NULL, P1, NULL); pthread_create(NULL, NULL, P2, NULL); __VERIFIER_atomic_begin(); main$tmp_guard0 = __unbuffered_cnt == 3; __VERIFIER_atomic_end(); __VERIFIER_assume(main$tmp_guard0); __VERIFIER_atomic_begin(); a = a$w_buff0_used && a$r_buff0_thd0 ? a$w_buff0 : (a$w_buff1_used && a$r_buff1_thd0 ? a$w_buff1 : a); a$w_buff0_used = a$w_buff0_used && a$r_buff0_thd0 ? FALSE : a$w_buff0_used; a$w_buff1_used = a$w_buff0_used && a$r_buff0_thd0 || a$w_buff1_used && a$r_buff1_thd0 ? FALSE : a$w_buff1_used; a$r_buff0_thd0 = a$w_buff0_used && a$r_buff0_thd0 ? FALSE : a$r_buff0_thd0; a$r_buff1_thd0 = a$w_buff0_used && a$r_buff0_thd0 || a$w_buff1_used && a$r_buff1_thd0 ? FALSE : a$r_buff1_thd0; __VERIFIER_atomic_end(); __VERIFIER_atomic_begin(); /* Program proven to be relaxed for X86, model checker says YES. */ main$tmp_guard1 = !(z == 2 && __unbuffered_p0_EAX == 1 && __unbuffered_p0_EBX == 0 && __unbuffered_p2_EAX == 2 && __unbuffered_p2_EBX == 0); __VERIFIER_atomic_end(); /* Program proven to be relaxed for X86, model checker says YES. */ __VERIFIER_assert(main$tmp_guard1); return 0; }
the_stack_data/25138258.c
#include <stdio.h> void test(int k); int main() { int i = 0; printf("The address of i is %x\n", &i); test(i); printf("The address of i is %x\n", &i); test(i); return 0; } void test(int k) { printf("The address of k is %x\n", &k); }
the_stack_data/173578499.c
#include<stdio.h> #include<string.h> void palindromo(char string[]){ char invertida[46]; int i=0,cont=0,j=(strlen(string)-1); int igual; cont=strlen(string); for(i=0;i<cont;i++,j--){ invertida[i]=string[j]; } invertida[strlen(string)]='\0'; igual=strcmp(string,invertida); if(igual==0) printf("Sim."); else printf("Nao."); } int main(){ char string[46]; printf("Digite uma palavra: "); scanf("%s",string); palindromo(string); }
the_stack_data/32949280.c
/* * @Author: HuangYuhui * @Date: 2019-02-09 18:06:41 * @Last Modified by: HuangYuhui * @Last Modified time: 2019-02-09 18:38:56 */ /* * ヾ(●´∀`●) * * 程序填空题 * * 函数'fun'的功能是 : 将'string_a'和'string_b'所指的两个字符串分别转换成面值相同的整数,并进行相加作为函数值返回. * 规定字符串中只含九个以下的数字字符. */ #include <stdio.h> #include <string.h> #include <ctype.h> //? int isdigit(); #define N 9 /* * Declare the method. */ static long ctod(char *string); static long fun(char *string_a, char *string_b); /* * Test the program. */ int main(int argc, char const *argv[]) { char string_a[N], string_b[N]; do { printf("PLEASE INPUT STRING-A : "); gets(string_a); } while (strlen(string_a) > N); // ? do { printf("\nPLEASE INPUT STRING-B : "); gets(string_b); } while (strlen(string_b) > N); printf("THE RESULT IS : %ld"); fun(string_a, string_b); getchar(); return 0; } /* * Defined the method. */ static long ctod(char *string) { long d = 0; /** * ? : isdigit() : Included the header file of '<ctype.h>'. * todo : Checks whether the argument is a decimal numeric character. */ if (isdigit(*string)) { /** * ! blank * ? Converts a string to an integer. */ d = d * 10 + *string - '0'; //! blank string++; } return d; } static long fun(char *string_a, char *string_b) { return ctod(string_a) + ctod(string_b); //! blank }
the_stack_data/40880.c
#include <stdio.h> int main() { int num1,num2; float result; char ch; //to store operator choice printf("enter first number:"); scanf("%d",&num1); printf("enter second number:"); scanf("%d",&num2); printf("choose operation to perform( +,-,*,/,%):"); scanf("%c",&ch); result=0; switch(ch) { case'+': result=num1+num2; break; case'-': result=num1-num2; break; case'*': result=num1*num2; break; case'/': result=num1/num2; break; case'%': result=num1%num2; break; default: printf("invalid operation.\n"); } printf("result:%d%c%d=%f\n",num1,ch,num2,result); return 0; }
the_stack_data/111076847.c
#include <stdio.h> #include <stdlib.h> #include <string.h> int main( int argc, char* argv[] ){ int arg1 = atoi(argv[1]); if (arg1 > 100 ){ fprintf(stderr, "Number too large\n"); exit( 1 ); } printf( "%d\n", arg1 ); return 0; }
the_stack_data/86908.c
/* * aoutmics.c -- Merge Image and saved Code State (a.out version) * Copyright (c) 1993 Applied Logic Systems, Inc. * * Author: Kevin A. Buettner * Created: 10-14-93 */ #include <a.out.h> /* #include <filehdr.h> */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> /* * MISSBUFSIZE is the size of the buffer used for copying the input image to * the output image. */ #define MISSBUFSIZE 16384 #undef round #define round(x,s) ((((long) (x) -1) & ~(long)((s)-1)) + (s)) /* * fe reports a fatal error and then exits. */ static void fe(char *mess, char *arg) { if (arg) fprintf(stderr,mess,arg); else fprintf(stderr,mess); fprintf(stderr,"\n"); exit(1); } /* * als_data_name is a character array containing the name of the segment * where we put the saved state in the elf file. */ static char als_data_name[] = "als_data"; /* * ss_symname contains the name of the symbol which we search for and fix up * to indicate the offset to the saved state data. */ static char ss_symname[] = "_saved_state_image_offset"; main(int argc,char **argv) { int iifd, ssfd, oifd; long nbytes; struct stat ss_statbuf; long ss_offset; long ss_size; struct exec ehdr; struct nlist *symtab, *sym; char *strtab, *name; long nsyms; char buf[MISSBUFSIZE]; # define iiname argv[1] # define ssname argv[2] # define oiname argv[3] if (argc != 4) fe("Usage: als-mics image-name saved-state-name output-image-name", 0); /* * Step 1: Copy the input image to the output image. */ iifd = open(iiname, O_RDONLY); if (iifd < 0) fe("Error opening %s for input", iiname); oifd = open(oiname, O_RDWR|O_CREAT|O_TRUNC, 0777); if (oifd < 0) fe("Error opening %s for output",oiname); while ( (nbytes = read(iifd, buf, MISSBUFSIZE)) ) { if (nbytes < 0) fe("Error encountered while reading %s", iiname); if (write(oifd, buf, nbytes) != nbytes) fe("Error encountered while writing to %s", oiname); } close(iifd); /* * Step 2: Open the save state file and stat it for future processing */ ssfd = open(ssname, O_RDONLY); if (ssfd < 0) fe("Error opening saved state file %s for read access", ssname); if (fstat(ssfd, &ss_statbuf) < 0) fe("Cannot fstat file descriptor associated with %s", ssname); /* * Step 3: Read the exec header. */ if ( lseek(oifd, 0, 0) < 0 || read(oifd, &ehdr, sizeof ehdr) < 0) fe("Cannot read header information", 0); if (N_BADMAG(ehdr)) fe("Bad magic value in header of %s", oiname); /* * Step 4: Read symbol and string tables */ nbytes = ehdr.a_syms; symtab = (struct nlist *) malloc(nbytes); fprintf(stderr,"ehdr.a_syms=%d nbytes=%d symtab=%d\n", ehdr.a_syms, nbytes,symtab); if (!symtab) fe("Unable to allocate sufficient space for symbol table", 0); if (lseek(oifd, N_SYMOFF(ehdr), 0) < 0) fe("Unable to seek to symbol table", 0); if (read(oifd, (char *) symtab, nbytes) != nbytes) fe("Unable to read symbol table", 0); if (read(oifd, (char *) &nbytes, 4) != 4) fe("Unable to read size of string table", 0); strtab = malloc(nbytes); if (!strtab) fe("Unable to allocate sufficient space for string table", 0); if (read(oifd, strtab+4, nbytes-4) != nbytes-4) fe("Unable to read string table",0); for (sym = symtab, nsyms = ehdr.a_syms / sizeof (struct nlist); nsyms; nsyms--, sym++) if ( sym->n_un.n_strx && strcmp(ss_symname, strtab + sym->n_un.n_strx) == 0) break; if (!nsyms) fe("Symbol %s not found in image.", ss_symname); if (!(N_DATADDR(ehdr) <= sym->n_value && sym->n_value < N_BSSADDR(ehdr))) fe("Integrity check between symbol value and section failed", 0); if (lseek(oifd, sym->n_value - N_DATADDR(ehdr) + N_DATOFF(ehdr), 0) < 0) fe("Unable to seek to value associated with symbol %s", ss_symname); if (read(oifd, &ss_offset, 4) != 4) fe("Unable to read value associated with symbol %s", ss_symname); if (ss_offset == 0) { long endoff = lseek(oifd, 0, 2); /* seek to end of file */ long pgsize = getpagesize(); if (endoff < 0) fe("Unable to seek to end of file %s", oiname); /* * We want to be able to use this code on systems with mmap. This * means that we must align the data on page boundaries. The following * line of code sets ss_offset to the next page boundary. */ ss_offset = round(endoff+4, pgsize); /* * For sections at the ends of files, the convention seems to be * to store the size of the section in the first four bytes followed * by the information that we wish to store. In the following * lines, we write this size information out along with a zero * filled area which will take us to where the saved state information * will live. */ ss_size = ss_statbuf.st_size + (ss_offset - endoff); bcopy(&ss_size, buf, 4); bzero(buf+4, ss_offset - endoff - 4); if (write(oifd, buf, ss_offset-endoff) < 0) fe("Error writing to %s", oiname); /* * Update the offset variable in the new image to be the value * for ss_offset that we just computed. This value being non- * zero will inform the image (when run) that there is a saved * state attached to the image. It also tells the image where * to find the saved state. */ if (lseek(oifd, sym->n_value - N_DATADDR(ehdr) + N_DATOFF(ehdr), 0) < 0) fe("Unable to seek to value associated with symbol %s", ss_symname); if (write(oifd, &ss_offset, 4) != 4) fe("Unable to write new value for symbol %s", ss_symname); } /* * Seek to start of saved state area */ if (lseek(oifd, ss_offset, 0) < 0) fe("Unable to seek to start of saved state area in %s", oiname); /* * copy the saved state file on to the end of the new image * file. */ while ( (nbytes = read(ssfd, buf, MISSBUFSIZE)) ) { if (nbytes < 0) fe("Error encountered while reading %s", ssname); if (write(oifd, buf, nbytes) != nbytes) fe("Error encountered while writing to %s", oiname); } close(ssfd); close (oifd); /* * Change the mode of the output image file to be the same as the input * image file. */ if (stat(iiname, &ss_statbuf) == 0) (void) chmod(oiname, ss_statbuf.st_mode); exit(0); }
the_stack_data/153267342.c
typedef char * caddr_t; typedef unsigned Cursor; typedef char *String; typedef struct _WidgetRec *Widget; typedef char Boolean; typedef unsigned int Cardinal; typedef struct _XedwListReturnStruct { String string; int xedwList_index; struct _XedwListReturnStruct *next; } XedwListReturnStruct; static XedwListReturnStruct *return_list; static String srcdir, dstdir; char *strcpy(); extern void setCursor(Cursor); extern void query_dialog(String, Boolean); extern Boolean directoryManagerNewDirectory(String); trashQueryResult(Widget w, Boolean delete, caddr_t call_data) { int execute(String, String, String, Boolean); extern void destroy_button_dialog(void); extern void changestate(Boolean); extern Cursor busy, left_ptr; extern String cwd; extern void freeReturnStruct(void); String rmstring; int status; XedwListReturnStruct *tmp; setCursor(busy); destroy_button_dialog(); if (delete == 1) { rmstring = (("rm -fr") != ((void *)0) ? (strcpy((char*)XtMalloc((unsigned)strlen("rm -fr") + 1), "rm -fr")) : ((void *)0)); tmp = return_list; while (tmp != ((void *)0)) { rmstring = (String) XtRealloc (rmstring, sizeof(char) * (strlen(rmstring) + strlen(tmp->string) + 5)); sprintf(rmstring, "%s '%s'", rmstring, tmp->string); tmp = tmp->next; } if ((status = execute(((void *)0), "rm", rmstring, 1)) != 0) { XBell(XtDisplay(w), 100); query_dialog("Can't remove file", 0); } XtFree(rmstring); directoryManagerNewDirectory(cwd); } else { changestate(1); } setCursor(left_ptr); freeReturnStruct(); } copyQueryResult(Widget w, Boolean copy, caddr_t call_data) { extern void destroy_button_dialog(); extern void changestate(Boolean); extern Cursor busy, left_ptr; extern void freeReturnStruct(void); int execute(String, String, String, Boolean); extern String cwd; String copystring; int status; Cardinal srclen, dstlen; XedwListReturnStruct *tmp; destroy_button_dialog(); setCursor(busy); if (copy == 1) { srclen = strlen(srcdir); dstlen = strlen(dstdir); copystring = (("cp -r") != ((void *)0) ? (strcpy((char*)XtMalloc((unsigned)strlen("cp -r") + 1), "cp -r")) : ((void *)0)); tmp = return_list; while (tmp != ((void *)0)) { copystring = (String) XtRealloc (copystring, sizeof(char) * (strlen(copystring) + strlen(tmp->string) + srclen + 6)); sprintf(copystring, "%s '%s/%s'", copystring, srcdir, tmp->string); tmp = tmp->next; } copystring = (String) XtRealloc (copystring, sizeof(char) * (strlen(copystring) + dstlen + 5)); sprintf(copystring, "%s '%s'", copystring, dstdir); if ((status = execute(((void *)0), "cp", copystring, 1)) != 0) { XBell(XtDisplay(w), 100); query_dialog("Can't copy file!", 0); } XtFree(copystring); directoryManagerNewDirectory(cwd); } else { changestate(1); } XtFree(srcdir); XtFree(dstdir); setCursor(left_ptr); freeReturnStruct(); } void freeReturnStruct(){}
the_stack_data/289012.c
/* The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? */ #include <stdio.h> #include <stdlib.h> long N=600851475143; struct node { struct node* next; int val; }; void next_prime(struct node *primes, int n) { char found = 0; struct node *aux = primes; while (!found) { if (n%aux->val == 0) { n++; aux = primes; } else { if (aux->next == NULL) { found = 1; aux->next = (struct node*) malloc(sizeof(struct node)); aux->next->val = n; aux->next->next = NULL; } else (aux = aux->next); } } } int main() { /* You can't malloc outside the main (or any function). Malloc allocates memory on the heap, i.e runtime, so you can't allocate on compile time. You can though declare the variable and it will be saved in the program page on compile time */ struct node *primes = (struct node*) malloc(sizeof(struct node)); primes->val = 2; primes->next = NULL; while (N > 1) { while (N%primes->val == 0) { N /= primes->val; } if (N>1) { next_prime(primes, primes->val); primes = primes->next; } } printf("%d\n", primes->val); return 0; }
the_stack_data/82951634.c
#include <stdio.h> int main() { char s[101], c; int i, j, num, n; scanf("%d", &n); for(int j = 0; j < n; j++) { scanf("%d", &num); scanf("%s", s); for(i = 0; i <= 100; i++) { c = s[i]; if(c == '\0') { break; } else if(c == 'w') { num = num + 3; } else if(c == 'c') { num = num / 2; if(num == 0) { break; } } } printf("%d\n", num); } return 0; }
the_stack_data/932444.c
double r_cosh(x) float *x; { double cosh(); return( cosh(*x) ); }
the_stack_data/61074958.c
/* Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory Written by Chunhua Liao, Pei-Hung Lin, Joshua Asplund, Markus Schordan, and Ian Karlin (email: [email protected], [email protected], [email protected], [email protected], [email protected]) LLNL-CODE-732144 All rights reserved. This file is part of DataRaceBench. For details, see https://github.com/LLNL/dataracebench. Please also see the LICENSE file for our additional BSD notice. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the disclaimer below. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the disclaimer (as noted below) in the documentation and/or other materials provided with the distribution. * Neither the name of the LLNS/LLNL nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Only the outmost loop can be parallelized. The inner loop has loop carried true data dependence. However, the loop is not parallelized so no race condition. */ int n=100, m=100; double b[100][100]; void foo() { int i,j; #pragma omp parallel for private(j) for (i=0;i<n;i++) for (j=1;j<m;j++) // Be careful about bounds of j b[i][j]=b[i][j-1]; } int main() { foo(); return 0; }
the_stack_data/173576707.c
// https://www.hackerrank.com/challenges/too-high-boxes/problem #include <stdio.h> #include <stdlib.h> #define MAX_HEIGHT 41 struct box { /** * Define three fields of type int: length, width and height */ int length; int width; int height; }; typedef struct box box; int get_volume(box b) { /** * Return the volume of the box */ return b.length * b.width * b.height; } int is_lower_than_max_height(box b) { /** * Return 1 if the box's height is lower than MAX_HEIGHT and 0 otherwise */ if (b.height < 41) { return 1; }else { return 0; } } int main() { int n; scanf("%d", &n); box *boxes = malloc(n * sizeof(box)); for (int i = 0; i < n; i++) { scanf("%d%d%d", &boxes[i].length, &boxes[i].width, &boxes[i].height); } for (int i = 0; i < n; i++) { if (is_lower_than_max_height(boxes[i])) { printf("%d\n", get_volume(boxes[i])); } } return 0; }
the_stack_data/248581623.c
#include <stdio.h> #include <string.h> int main() { struct { float x; float y; } coord; FILE* readptr; readptr = fopen ("coord.txt", "r"); FILE* writeptr; writeptr = fopen ("coord.bin", "wb"); char read_in[100]; for (int i = 0; i < 4; ++i) { fgets (read_in, 100, readptr); read_in[strcspn (read_in, "\r\n")] = 0; sscanf (read_in, "%f %f", &coord.x, &coord.y); printf ("%1.1f %1.1f \n", coord.x, coord.y); fwrite (&coord, sizeof (coord), 1, writeptr); } fclose (readptr); fclose (writeptr); return 0; }
the_stack_data/153268354.c
/*************************************************************** * * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department, * University of Wisconsin-Madison, WI. * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You may * obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ***************************************************************/ /* Generate a coredump. */ #if defined( Solaris27 ) || defined( Solaris26 ) #define __EXTENSIONS__ #endif #if defined( LINUX ) #define _XOPEN_SOURCE #endif #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main() { int i; int j; char *foo = (char *)0; j = 0; printf( "About to divide by zero\n"); fflush( stdout ); fsync( fileno(stdout) ); i = 1 / j; printf( "Error: didn't coredump from divide by zero!!!\n"); fflush( stdout ); fsync( fileno(stdout) ); *foo = 'a'; printf( "Error: didn't coredump from dereferencing NULL!!!\n"); fflush( stdout ); fsync( fileno(stdout) ); /* let's try this */ abort(); exit( 1 ); }
the_stack_data/108023.c
#include <netdb.h> #include <netinet/in.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #define MAX 80 #define PORT 8080 #define SA struct sockaddr /* Function designed for chat between client and server. */ void func(int sockfd) { char buff[MAX]; int n; /* infinite loop for chat */ for (;;) { bzero(buff, MAX); /* read the message from client and copy it in buffer */ read(sockfd, buff, sizeof(buff)); /* print buffer which contains the client contents */ printf("From client: %s\t To client : ", buff); bzero(buff, MAX); n = 0; /* copy server message in the buffer */ while ((buff[n++] = getchar()) != '\n'); /* and send that buffer to client */ write(sockfd, buff, sizeof(buff)); /* if msg contains "Exit" then server exit and chat ended. */ if (strncmp("exit", buff, 4) == 0) { printf("Server Exit...\n"); break; } } } /* Driver function */ int main() { int sockfd, connfd, len; struct sockaddr_in servaddr, cli; /* socket create and verification */ sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd == -1) { printf("socket creation failed...\n"); exit(EXIT_FAILURE); } else printf("Socket successfully created..\n"); bzero(&servaddr, sizeof(servaddr)); /* assign IP, PORT */ servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(PORT); /* Binding newly created socket to given IP and verification */ if ((bind(sockfd, (SA *) &servaddr, sizeof(servaddr))) != 0) { printf("socket bind failed...\n"); exit(EXIT_FAILURE); } else printf("Socket successfully binded..\n"); /* Now server is ready to listen and verification */ if ((listen(sockfd, 5)) != 0) { printf("Listen failed...\n"); exit(0); } else printf("Server listening..\n"); len = sizeof(cli); /* Accept the data packet from client and verification */ connfd = accept(sockfd, (SA *) &cli, &len); if (connfd < 0) { printf("server acccept failed...\n"); exit(EXIT_FAILURE); } else printf("server acccept the client...\n"); /* Function for chatting between client and server */ func(connfd); /* After chatting close the socket */ close(sockfd); return EXIT_SUCCESS; }
the_stack_data/86075054.c
/* PR target/63594 */ /* { dg-do compile } */ /* { dg-options "-O2 -Wno-psabi" } */ /* { dg-additional-options "-mno-mmx" { target i?86-*-* x86_64-*-* } } */ /* { dg-prune-output "non-standard ABI extension" } */ #define C1 c #define C2 C1, C1 #define C4 C2, C2 #define C8 C4, C4 #define C16 C8, C8 #define C32 C16, C16 #define C64 C32, C32 #define C_(n) n #define C(n) C_(C##n) #define T(t,s) \ typedef t v##t##s __attribute__ ((__vector_size__ (s * sizeof (t)))); \ v##t##s \ test1##t##s (t c) \ { \ v##t##s v = { C(s) }; \ return v; \ } \ \ v##t##s \ test2##t##s (t *p) \ { \ t c = *p; \ v##t##s v = { C(s) }; \ return v; \ } typedef long long llong; T(char, 64) T(char, 32) T(char, 16) T(char, 8) T(char, 4) T(char, 2) T(char, 1) T(short, 32) T(short, 16) T(short, 8) T(short, 4) T(short, 2) T(short, 1) T(int, 16) T(int, 8) T(int, 4) T(int, 2) T(int, 1) T(float, 16) T(float, 8) T(float, 4) T(float, 2) T(float, 1) T(llong, 8) T(llong, 4) T(llong, 2) T(llong, 1) T(double, 8) T(double, 4) T(double, 2) T(double, 1)
the_stack_data/96852.c
#include <stdio.h> #include "stdlib.h" int main() { int n; printf("Input the number of elements to store in the array: \n"); scanf("%d", &n); int arr[n]; printf("Input %d number of elements in the array :\n", n); for (int i = 0; i <=n; i++) { printf("Type element %d: ", i); scanf("%d", arr+i); } for (int i = 0; i < n; ++i) { printf("element %d : %d\n", i, *arr+i); } return 0; }
the_stack_data/39010.c
/* Copyright (C) 2000, 2004 Free Software Foundation. Ensure all expected transformations of builtin strcspn occur and perform correctly. Written by Kaveh R. Ghazi, 11/27/2000. */ extern void abort (void); typedef __SIZE_TYPE__ size_t; extern size_t strcspn (const char *, const char *); extern char *strcpy (char *, const char *); void main_test (void) { const char *const s1 = "hello world"; char dst[64], *d2; if (strcspn (s1, "hello") != 0) abort(); if (strcspn (s1, "z") != 11) abort(); if (strcspn (s1+4, "z") != 7) abort(); if (strcspn (s1, "hello world") != 0) abort(); if (strcspn (s1, "") != 11) abort(); strcpy (dst, s1); if (strcspn (dst, "") != 11) abort(); strcpy (dst, s1); d2 = dst; if (strcspn (++d2, "") != 10 || d2 != dst+1) abort(); strcpy (dst, s1); d2 = dst; if (strcspn (++d2+5, "") != 5 || d2 != dst+1) abort(); if (strcspn ("", s1) != 0) abort(); strcpy (dst, s1); if (strcspn ("", dst) != 0) abort(); strcpy (dst, s1); d2 = dst; if (strcspn ("", ++d2) != 0 || d2 != dst+1) abort(); strcpy (dst, s1); d2 = dst; if (strcspn ("", ++d2+5) != 0 || d2 != dst+1) abort(); /* Test at least one instance of the __builtin_ style. We do this to ensure that it works and that the prototype is correct. */ if (__builtin_strcspn (s1, "z") != 11) abort(); }
the_stack_data/167331945.c
/* -*- Mode: C; c-basic-offset:4 ; -*- */ /* $Id$ * * (C) 2002 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ #include <stdio.h> /* This is a test program, so we allow printf */ /* style: allow:printf:3 sig:0 */ extern int MPIU_Snprintf( char *, size_t, const char *, ... ); int main( int argc, char *argv[] ) { char buf[1000]; int n; n = MPIU_Snprintf( buf, 100, "This is a test\n" ); printf( "%d:%s", n, buf ); n = MPIU_Snprintf( buf, 100, "This is a test %d\n", 3000000 ); printf( "%d:%s", n, buf ); n = MPIU_Snprintf( buf, 100, "This %s %% %d\n", "is a test for ", -3000 ); printf( "%d:%s", n, buf ); return 0; }
the_stack_data/7949765.c
/** * Copyright (c) 2019 - Andrew C. Pacifico - All Rights Reserved. * @author Andrew C. Pacifico <[email protected]> */ #include <stdio.h> void reverse(int* arr, int* pos, int i, int j) { int aux; while (i < j) { aux = arr[i]; arr[i] = arr[j]; arr[j] = aux; pos[arr[j]] = j; pos[arr[i]] = i; i++; j--; } } int main() { int arr[50000], pos[50000]; int n, r, q, count = 1, i, j, x; scanf("%d", &n); while (n != 0) { for (i = 0; i < n; i++) { arr[i] = i; pos[i] = i; } scanf("%d", &r); while (r--) { scanf("%d%d", &i, &j); reverse(arr, pos, i - 1, j - 1); } printf("Genome %d\n", count++); scanf("%d", &q); while (q--) { scanf("%d", &x); printf("%d\n", (pos[x - 1]) + 1); } scanf("%d", &n); } return 0; }
the_stack_data/38398.c
// MLP2 - TWO-LAYER MULTILAYER PERCEPTRON - SAMPLE IMPLEMENTATION (WITH THE XOR DATA) // compile: gcc -Wall -std=gnu99 -O3 -ffast-math -funroll-loops -s -o NNTrain NNTrain.c -lm // Version 1.0 ----------------------------------------- Copyleft R.JAKSA 2009, GPLv3 #define Nin 2304 // no. of inputs #define Nh1 3 // no. of hidden units #define Nou 2 // no. of outputs #define Gamma 0.2 // learning rate #define Epochs 10000 // no. of training epochs (cycles) // ------------------------------------------------------------- END OF CONFIGURATION #include <math.h> // fabs, exp #include <stdlib.h> // rand, srand #include <stdio.h> // printf, fgets, sscanf, fopen #include <sys/timeb.h> // ftime #include <string.h> // strtok #define Nx 1+Nin+Nh1+Nou // no. of units #define IN1 1 // 1st input #define INn Nin // last (n-th) input #define H11 Nin+1 // 1st hidden #define H1n Nin+Nh1 // last hidden #define OU1 Nin+Nh1+1 // 1st output #define OU2 Nin+Nh1+2 // 2nd output #define OUn Nin+Nh1+Nou // last output typedef struct { double x[Nx]; // units inputs double y[Nx]; // units activations double delta[Nx]; // units delta signal double w[Nx][Nx]; // weights double dv[Nx]; // desired value on output !!! TODO: Nou is enough } ann_t; #define w(i,j) ann->w[i][j] #define x(i) ann->x[i] #define y(i) ann->y[i] #define delta(i) ann->delta[i] #define dv(i) ann->dv[i] // --------------------------------------- ACTIVATION FUNCTION AND ITS 1st DERIVATION #define af(X) (1.0/(1.0+exp((-1.0)*(X)))) #define df(X) (exp((-1.0)*(X))/((1.0+exp((-1.0)*(X)))*(1.0+exp((-1.0)*(X))))) // -------------------------------------------------------- SINGLE LAYER WEIGHTS INIT static void layer_rnd_init(ann_t *ann, int i1, int in, int j1, int jn, // output/input block from-to double min, double max) { // weights init interval size for(int i=i1; i<=in; i++) { w(i,0) = rand() / (RAND_MAX/(max-min)) + min; for(int j=j1; j<=jn; j++) { w(i,j) = rand() / (RAND_MAX/(max-min)) + min; } } } // ---------------------------------------------------------------- MLP2 WEIGHTS INIT void MLP2_rnd_init(ann_t *ann, double min, double max) { y(0)=-1.0; // the input for bias for(int i=0; i<Nx; i++) { for(int j=0; j<Nx; j++) { w(i,j)=0; // all weights to zero } } layer_rnd_init(ann,H11,H1n,IN1,INn,min,max); // in -> h1 layer_rnd_init(ann,OU1,OUn,H11,H1n,min,max); // h1 -> ou } // ----------------------------------------------------------------- SINGLE LAYER RUN static void layer_run(ann_t *ann, int i1, int in, int j1, int jn) { // output/input block from-to for(int i=i1; i<=in; i++) { x(i) = w(i,0) * y(0); // add bias contribution for(int j=j1; j<=jn; j++) { x(i) += w(i,j) * y(j); // add main inputs contrib. } y(i) = af(x(i)); // apply activation function } } // ---------------------------------------------------------------------- NETWORK RUN void MLP2_run(ann_t *ann) { layer_run(ann,H11,H1n,IN1,INn); // in -> h1 layer_run(ann,OU1,OUn,H11,H1n); // h1 -> ou } // ------------------------------------------------------ SINGLE LAYER WEIGHTS UPDATE static void layer_weights_update(ann_t *ann, int i1, int in, int j1, int jn, // output/input block from-to double gamma) { // learning rate for(int i=i1; i<=in; i++) { w(i,0) += gamma * delta(i) * y(0); // bias (weight) update for(int j=j1; j<=jn; j++) { w(i,j) += gamma * delta(i) * y(j); // the weights update } } } // ------------------------------------------------- VANILLA BACKPROPAGATION LEARNING void MLP2_vanilla_bp(ann_t *ann, double gamma) { MLP2_run(ann); // 1st run the network for(int i=OU1; i<=OUn; i++) { delta(i) = (dv(i)-y(i)) * df(x(i)); // delta on output layer } for(int i=H11; i<=H1n; i++) { double S=0.0; for(int h=OU1; h<=OUn; h++) { S += delta(h) * w(h,i); } delta(i) = S * df(x(i)); // delta on hidden layer } layer_weights_update(ann,OU1,OUn,H11,H1n,gamma); // h1 -> ou layer_weights_update(ann,H11,H1n,IN1,INn,gamma); // in -> h1 } void write_weights_to_file(ann_t *ann, int i1, int in, int j1, int jn, FILE *f_weights) { // output/input block from-to for(int i=i1; i<=in; i++) { fprintf(f_weights, "%.8f\n", w(i,0)); for(int j=j1; j<=jn; j++) { fprintf(f_weights, "%.8f\n", w(i,j)); } } } // ----------------------------------------------------------------------------- MAIN int main(void) { ann_t *ann=(ann_t*)malloc(sizeof(ann_t)); FILE *f_images, *f_joints, *f_weights; // file inputs/output char image_line[100000], joint_line[100]; // one line from image/joint file char *rgb_str; // rgb value as string double rgb_value; // rgb value as number double joint1, joint2; // joint values struct timeb t; ftime(&t); srand(42);//srand(t.time); // time-seed random generator MLP2_rnd_init(ann,-0.1,0.1); // initialize the network for(int e=0; e<=Epochs; e++) { // for every epoch double err1=0.0, err2=0.0; // total errors in one epoch int data = 0; // number of input data files f_images=fopen("images.txt", "r"); f_joints=fopen("joints.txt", "r"); if(f_images == NULL || f_joints == NULL) { printf("ERROR: Files images.txt or joints.txt did not open correctly"); return(1); } while(fgets(image_line, 100000, f_images) != NULL) { // read every image until end of file fgets(joint_line, 100, f_joints); // also read joints for that image int input_index=IN1; rgb_str=strtok(image_line, " "); // read first rgb value while(rgb_str != NULL) { sscanf(rgb_str, "%lf", &rgb_value); y(input_index)=rgb_value; // save rgb value input_index++; rgb_str=strtok(NULL, " "); // read rgb values until string comes to an end } sscanf(joint_line, "%lf %lf", &joint1, &joint2); // read joint values for read image dv(OU1)=joint1; dv(OU2)=joint2; // store joint values as desired output MLP2_vanilla_bp(ann,Gamma); // train MLP2_run(ann); // run network double J1=fabs(dv(OU1) - y(OU1)); // compute the error double J2=fabs(dv(OU2) - y(OU2)); err1 += J1; err2 += J2; data++; if(e%100==0) { // every 100 ep. print error printf("%5d: %f %f (%.6f) %f %f (%.6f)\n",e,y(OU1),dv(OU1),J1,y(OU2),dv(OU2),J2); } } fclose(f_images); fclose(f_joints); if ((err1 / data < 0.005) && (err2 / data < 0.005)) { printf("%d: %f %f\n", e, err1 / data, err2 / data); break; } } f_weights=fopen("weights.txt", "w"); write_weights_to_file(ann,H11,H1n,IN1,INn,f_weights); // in -> h1 write_weights_to_file(ann,OU1,OUn,H11,H1n,f_weights); // h1 -> ou fclose(f_weights); free(ann); return(0); } // ------------------------------------------------------------------------------ END
the_stack_data/130629.c
/* Copyright (C) 1992, 1995, 1997 Aladdin Enterprises. All rights reserved. This file is part of Aladdin Ghostscript. Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or distributor accepts any responsibility for the consequences of using it, or for whether it serves any particular purpose or works at all, unless he or she says so in writing. Refer to the Aladdin Ghostscript Free Public License (the "License") for full details. Every copy of Aladdin Ghostscript must include a copy of the License, normally in a plain ASCII text file named PUBLIC. The License grants you the right to copy, modify and redistribute Aladdin Ghostscript, but only under certain conditions described in the License. Among other things, the License requires that the copyright notice and this notice be preserved on all copies. */ /* echogs.c */ /* 'echo'-like utility */ #include <stdio.h> /* Some brain-damaged environments (e.g. Sun) don't include */ /* prototypes for fputc/fputs in stdio.h! */ extern int fputc(), fputs(); /* Some systems have time_t in sys/types.h rather than time.h. */ #include <sys/types.h> #include <ctype.h> #include <string.h> #include <time.h> /* for ctime */ /* The VMS environment uses different values for success/failure exits: */ #ifdef VMS #include <stdlib.h> # define exit_OK 1 # define exit_FAILED 18 #else # define exit_OK 0 # define exit_FAILED 1 #endif /* * This program exists solely to get around omissions, problems, and * incompatibilities in various shells and utility environments. * Don't count on it staying the same from one release to another! */ /* * Usage: echogs [-e .extn] [-(w|a)[b][-] file] [-h] [-n] (-d|-D | -f|-F | -x hexstring | -(l|q|Q) string | -(l|q|Q)string | -s | -u string | -i | -r file | -R file | -X)* [-] string* * Echoes string(s), or the binary equivalent of hexstring(s). * If -w, writes to file; if -a, appends to file; if neither, * writes to stdout. -wb and -ab open the file in binary mode. * -w and -a search forward for the next argument that is not a switch. * An appended - means the same as - alone, taking effect after the file * argument. * -e specifies an extension to be added to the file name. * If -h, write the output in hex instead of literally. * If -n, does not append a newline to the output. * -d or -D means insert the date and time. * -f or -F means insert the file name passed as the argument of -w or -a. * -q means write the next string literally. * -l or -Q means the same as -q followed by -s. * -s means write a space. * -u means convert the next string to upper case. * -i means read from stdin, treating each line as an argument. * -r means read from a named file in the same way. * -R means copy a named file with no interpretation * (but convert to hex if -h is in effect). * -X means treat any following literals as hex rather than string data. * - alone means treat the rest of the line as literal data, * even if the first string begins with a -. * -+<letter> is equivalent to -<Letter>, i.e., it upper-cases the letter. * Inserts spaces automatically between the trailing strings, * but nowhere else; in particular, echogs -q a b * writes 'ab', in contrast to echogs -q a -s b * which writes 'a b'. */ static int hputc(), hputs(); main(int argc, char *argv[]) { FILE *out = stdout; FILE *in; char *extn = ""; char fmode[4]; #define FNSIZE 100 char *fnparam; char fname[FNSIZE]; int newline = 1; int interact = 0; int (*eputc)() = fputc, (*eputs)() = fputs; #define LINESIZE 1000 char line[LINESIZE]; char sw = 0, sp = 0, hexx = 0; char **argp = argv + 1; int nargs = argc - 1; if ( nargs > 0 && !strcmp(*argp, "-e") ) { if ( nargs < 2 ) return 1; extn = argp[1]; argp += 2, nargs -= 2; } if ( nargs > 0 && (*argp)[0] == '-' && ((*argp)[1] == 'w' || (*argp)[1] == 'a') ) { size_t len = strlen(*argp); int i; if ( len > 4 ) return 1; for ( i = 1; i < nargs; i++ ) if ( argp[i][0] != '-' ) break; if ( i == nargs ) return 1; fnparam = argp[i]; strcpy(fmode, *argp + 1); strcpy(fname, fnparam); strcat(fname, extn); if ( fmode[len-2] == '-' ) { fmode[len-2] = 0; argp[i] = "-"; argp++, nargs--; } else { for ( ; i > 1; i-- ) argp[i] = argp[i-1]; argp += 2, nargs -= 2; } } else strcpy(fname, ""); if ( nargs > 0 && !strcmp(*argp, "-h") ) { eputc = hputc, eputs = hputs; argp++, nargs--; } if ( nargs > 0 && !strcmp(*argp, "-n") ) { newline = 0; argp++, nargs--; } if ( strlen(fname) != 0 ) { out = fopen(fname, fmode); if ( out == 0 ) return 1; } while ( 1 ) { char *arg; if ( interact ) { if ( fgets(line, LINESIZE, in) == NULL ) { interact = 0; if ( in != stdin ) fclose(in); continue; } /* Remove the terminating \n. */ line[strlen(line) - 1] = 0; arg = line; } else { if ( nargs == 0 ) break; arg = *argp; argp++, nargs--; } if ( sw == 0 && arg[0] == '-' ) { char chr = arg[1]; sp = 0; swc: switch ( chr ) { case '+': /* upper-case command */ ++arg; chr = toupper(arg[1]); goto swc; case 'l': /* literal string, then -s */ chr = 'Q'; /* falls through */ case 'q': /* literal string */ case 'Q': /* literal string, then -s */ if ( arg[2] != 0 ) { (*eputs)(arg + 2, out); if ( chr == 'Q' ) (*eputc)(' ', out); break; } /* falls through */ case 'r': /* read from a file */ case 'R': case 'u': /* upper-case string */ case 'x': /* hex string */ sw = chr; break; case 's': /* write a space */ (*eputc)(' ', out); break; case 'i': /* read interactively */ interact = 1; in = stdin; break; case 'd': /* insert date/time */ case 'D': { time_t t; char str[26]; time(&t); strcpy(str, ctime(&t)); str[24] = 0; /* remove \n */ (*eputs)(str, out); } break; case 'f': /* insert file name */ case 'F': (*eputs)(fnparam, out); break; case 'X': /* treat literals as hex */ hexx = 1; break; case 0: /* just '-' */ sw = '-'; break; } } else switch ( sw ) { case 0: case '-': if ( hexx ) goto xx; if ( sp ) (*eputc)(' ', out); (*eputs)(arg, out); sp = 1; break; case 'q': sw = 0; (*eputs)(arg, out); break; case 'Q': sw = 0; (*eputs)(arg, out); (*eputc)(' ', out); break; case 'r': sw = 0; in = fopen(arg, "r"); if ( in == NULL ) exit(exit_FAILED); interact = 1; break; case 'R': sw = 0; in = fopen(arg, "r"); if ( in == NULL ) exit(exit_FAILED); { int count; while ( (count = fread(line, 1, 1, in)) > 0 ) (*eputc)(line[0], out); } fclose(in); break; case 'u': { const char *up; for ( up = arg; *up; up++ ) (*eputc)(toupper(*up), out); } sw = 0; break; case 'x': xx: { char *xp; unsigned int xchr = 1; for ( xp = arg; *xp; xp++ ) { char ch = *xp; if ( !isxdigit(ch) ) return 1; xchr <<= 4; xchr += (isdigit(ch) ? ch - '0' : (isupper(ch) ? tolower(ch) : ch) - 'a' + 10); if ( xchr >= 0x100 ) { (*eputc)(xchr & 0xff, out); xchr = 1; } } } sw = 0; break; } } if ( newline ) (*eputc)('\n', out); if ( out != stdout ) fclose(out); return exit_OK; } static int hputc(int ch, FILE *out) { static char *hex = "0123456789abcdef"; putc(hex[ch >> 4], out); putc(hex[ch & 0xf], out); return 0; } static int hputs(char *str, FILE *out) { while ( *str ) hputc(*str++ & 0xff, out); return 0; }
the_stack_data/23574792.c
/* Exercise 1 - Calculations Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */ #include <stdio.h> int main() { float mark1, mark2, avg; printf("Enter the first mark : "); scanf("%f", &mark1); printf("Enter the second mark : "); scanf("%f", &mark2); printf("The first mark entered is : %.2f\n", mark1); printf("The second mark entered is : %.2f\n", mark2); avg = (mark1 + mark2)/2; printf("The average is : %.2f", avg); return 0; }
the_stack_data/40762350.c
#ifdef COMPILE_FOR_TEST #include <assert.h> #define assume(cond) assert(cond) #endif void main(int argc, char* argv[]) { int x_0_0;//sh_buf.outcnt int x_0_1;//sh_buf.outcnt int x_0_2;//sh_buf.outcnt int x_0_3;//sh_buf.outcnt int x_0_4;//sh_buf.outcnt int x_0_5;//sh_buf.outcnt int x_1_0;//sh_buf.outbuf[0] int x_1_1;//sh_buf.outbuf[0] int x_2_0;//sh_buf.outbuf[1] int x_2_1;//sh_buf.outbuf[1] int x_3_0;//sh_buf.outbuf[2] int x_3_1;//sh_buf.outbuf[2] int x_4_0;//sh_buf.outbuf[3] int x_4_1;//sh_buf.outbuf[3] int x_5_0;//sh_buf.outbuf[4] int x_5_1;//sh_buf.outbuf[4] int x_6_0;//sh_buf.outbuf[5] int x_7_0;//sh_buf.outbuf[6] int x_8_0;//sh_buf.outbuf[7] int x_9_0;//sh_buf.outbuf[8] int x_10_0;//sh_buf.outbuf[9] int x_11_0;//LOG_BUFSIZE int x_11_1;//LOG_BUFSIZE int x_12_0;//CREST_scheduler::lock_0 int x_12_1;//CREST_scheduler::lock_0 int x_12_2;//CREST_scheduler::lock_0 int x_12_3;//CREST_scheduler::lock_0 int x_12_4;//CREST_scheduler::lock_0 int x_13_0;//t3 T0 int x_14_0;//t2 T0 int x_15_0;//arg T0 int x_16_0;//functioncall::param T0 int x_16_1;//functioncall::param T0 int x_17_0;//buffered T0 int x_18_0;//functioncall::param T0 int x_18_1;//functioncall::param T0 int x_19_0;//functioncall::param T0 int x_19_1;//functioncall::param T0 int x_20_0;//functioncall::param T0 int x_20_1;//functioncall::param T0 int x_20_2;//functioncall::param T0 int x_20_3;//functioncall::param T0 int x_20_4;//functioncall::param T0 int x_21_0;//functioncall::param T0 int x_21_1;//functioncall::param T0 int x_21_2;//functioncall::param T0 int x_22_0;//direction T0 int x_23_0;//functioncall::param T0 int x_23_1;//functioncall::param T0 int x_23_2;//functioncall::param T0 int x_24_0;//functioncall::param T0 int x_24_1;//functioncall::param T0 int x_25_0;//functioncall::param T0 int x_25_1;//functioncall::param T0 int x_26_0;//functioncall::param T0 int x_26_1;//functioncall::param T0 int x_27_0;//functioncall::param T0 int x_27_1;//functioncall::param T0 int x_28_0;//functioncall::param T0 int x_28_1;//functioncall::param T0 int x_29_0;//functioncall::param T0 int x_29_1;//functioncall::param T0 int x_30_0;//functioncall::param T0 int x_30_1;//functioncall::param T0 int x_31_0;//functioncall::param T0 int x_31_1;//functioncall::param T0 int x_32_0;//functioncall::param T0 int x_32_1;//functioncall::param T0 int x_33_0;//functioncall::param T0 int x_33_1;//functioncall::param T0 int x_34_0;//functioncall::param T0 int x_34_1;//functioncall::param T0 int x_35_0;//functioncall::param T1 int x_35_1;//functioncall::param T1 int x_36_0;//functioncall::param T1 int x_36_1;//functioncall::param T1 int x_37_0;//i T1 int x_37_1;//i T1 int x_37_2;//i T1 int x_38_0;//rv T1 int x_39_0;//rv T1 int x_40_0;//blocksize T1 int x_40_1;//blocksize T1 int x_41_0;//functioncall::param T1 int x_41_1;//functioncall::param T1 int x_41_2;//functioncall::param T1 int x_42_0;//apr_thread_mutex_lock::rv T1 int x_42_1;//apr_thread_mutex_lock::rv T1 int x_43_0;//functioncall::param T1 int x_43_1;//functioncall::param T1 int x_44_0;//status T1 int x_44_1;//status T1 int x_45_0;//functioncall::param T1 int x_45_1;//functioncall::param T1 int x_46_0;//functioncall::param T1 int x_46_1;//functioncall::param T1 int x_47_0;//functioncall::param T1 int x_47_1;//functioncall::param T1 int x_48_0;//functioncall::param T1 int x_48_1;//functioncall::param T1 int x_49_0;//functioncall::param T1 int x_49_1;//functioncall::param T1 int x_50_0;//functioncall::param T1 int x_50_1;//functioncall::param T1 int x_51_0;//functioncall::param T2 int x_51_1;//functioncall::param T2 int x_52_0;//functioncall::param T2 int x_52_1;//functioncall::param T2 int x_53_0;//i T2 int x_53_1;//i T2 int x_53_2;//i T2 int x_53_3;//i T2 int x_54_0;//rv T2 int x_55_0;//rv T2 int x_55_1;//rv T2 int x_56_0;//blocksize T2 int x_56_1;//blocksize T2 int x_57_0;//functioncall::param T2 int x_57_1;//functioncall::param T2 int x_57_2;//functioncall::param T2 int x_58_0;//apr_thread_mutex_lock::rv T2 int x_58_1;//apr_thread_mutex_lock::rv T2 int x_59_0;//functioncall::param T2 int x_59_1;//functioncall::param T2 int x_60_0;//status T2 int x_60_1;//status T2 int x_61_0;//functioncall::param T2 int x_61_1;//functioncall::param T2 int x_62_0;//functioncall::param T2 int x_62_1;//functioncall::param T2 int x_63_0;//functioncall::param T2 int x_63_1;//functioncall::param T2 int x_64_0;//functioncall::param T2 int x_64_1;//functioncall::param T2 int x_65_0;//functioncall::param T2 int x_65_1;//functioncall::param T2 int x_65_2;//functioncall::param T2 int x_66_0;//functioncall::param T2 int x_66_1;//functioncall::param T2 int x_67_0;//functioncall::param T2 int x_67_1;//functioncall::param T2 int x_68_0;//functioncall::param T2 int x_68_1;//functioncall::param T2 T_0_0_0: x_0_0 = 0; T_0_1_0: x_1_0 = 0; T_0_2_0: x_2_0 = 0; T_0_3_0: x_3_0 = 0; T_0_4_0: x_4_0 = 0; T_0_5_0: x_5_0 = 0; T_0_6_0: x_6_0 = 0; T_0_7_0: x_7_0 = 0; T_0_8_0: x_8_0 = 0; T_0_9_0: x_9_0 = 0; T_0_10_0: x_10_0 = 0; T_0_11_0: x_11_0 = 0; T_0_12_0: x_13_0 = 4074974784; T_0_13_0: x_14_0 = 1009652320; T_0_14_0: x_15_0 = 0; T_0_15_0: x_16_0 = 664753493; T_0_16_0: x_16_1 = -1; T_0_17_0: x_17_0 = 0; T_0_18_0: x_18_0 = 1349856100; T_0_19_0: x_18_1 = x_17_0; T_0_20_0: x_19_0 = 425639036; T_0_21_0: x_19_1 = 97; T_0_22_0: x_20_0 = 983962017; T_0_23_0: x_20_1 = 0; T_0_24_0: x_21_0 = 813114463; T_0_25_0: x_21_1 = 0; T_0_26_0: x_22_0 = 1009647680; T_0_27_0: x_23_0 = 1753959921; T_0_28_0: x_23_1 = x_22_0; T_0_29_0: x_24_0 = 716325562; T_0_30_0: x_24_1 = 0; T_0_31_0: x_12_0 = -1; T_0_32_0: x_0_1 = 5; T_0_33_0: x_1_1 = 72; T_0_34_0: x_2_1 = 69; T_0_35_0: x_3_1 = 76; T_0_36_0: x_4_1 = 76; T_0_37_0: x_5_1 = 79; T_0_38_0: x_25_0 = 1097203927; T_0_39_0: x_25_1 = 83; T_0_40_0: x_26_0 = 1232878566; T_0_41_0: x_26_1 = 1; T_0_42_0: x_27_0 = 774703398; T_0_43_0: x_27_1 = 1; T_0_44_0: x_28_0 = 2079121650; T_0_45_0: x_28_1 = 1; T_0_46_0: x_29_0 = 1984066283; T_0_47_0: x_29_1 = 82; T_0_48_0: x_30_0 = 2076964805; T_0_49_0: x_30_1 = 90; T_0_50_0: x_31_0 = 589499144; T_0_51_0: x_31_1 = 1; T_0_52_0: x_32_0 = 1860491164; T_0_53_0: x_32_1 = 1; T_0_54_0: x_33_0 = 1203758734; T_0_55_0: x_33_1 = 2; T_0_56_0: x_34_0 = 2020110744; T_0_57_0: x_34_1 = 2; T_0_58_0: x_11_1 = 5; T_1_59_1: x_35_0 = 1275656167; T_1_60_1: x_35_1 = x_27_1; T_1_61_1: x_36_0 = 607638848; T_1_62_1: x_36_1 = x_28_1; T_1_63_1: x_37_0 = 0; T_1_64_1: x_38_0 = -1058209279; T_2_65_2: x_51_0 = 1551039161; T_2_66_2: x_51_1 = x_33_1; T_2_67_2: x_52_0 = 350154985; T_2_68_2: x_52_1 = x_34_1; T_2_69_2: x_53_0 = 0; T_2_70_2: x_54_0 = -1060310527; T_2_71_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0) x_55_0 = 1016715184; T_2_72_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_56_0 = 10963; T_2_73_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_57_0 = 818225599; T_2_74_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_57_1 = x_0_1; T_2_75_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_57_1) x_58_0 = 0; T_1_76_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_39_0 = 1016715184; T_1_77_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_40_0 = 10963; T_1_78_1: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_57_1 && 0 == x_12_0 + 1) x_12_1 = 2; T_1_79_1: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_57_1 && 2 == x_12_1) x_58_1 = 0; T_2_80_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_23_1 == 0 && 2 == x_12_1) x_59_0 = 2118380571; T_2_81_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_23_1 == 0 && 2 == x_12_1) x_59_1 = x_20_1 + -1*x_21_1 + x_24_1; T_2_82_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_23_1 == 0 && 2 == x_12_1) x_20_2 = 0; T_2_83_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_23_1 == 0 && 2 == x_12_1) x_21_2 = 0; T_2_84_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_23_1 == 0 && 2 == x_12_1) x_23_2 = 1; T_2_85_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 2 == x_12_1) x_55_1 = 0; T_2_86_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_55_1 && 2 == x_12_1) x_56_1 = x_57_1; T_2_87_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_55_1 && 2 == x_12_1) x_20_3 = x_20_2 + x_56_1; T_2_88_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_55_1 && 2 == x_12_1) x_57_2 = -1*x_56_1 + x_57_1; T_2_89_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_57_2 <= 0 && 2 == x_12_1) x_60_0 = 0; T_2_90_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_57_2 <= 0 && 2 == x_12_1) x_12_2 = -1; T_2_91_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_41_0 = 2042029725; T_2_92_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_41_1 = x_0_1; T_2_93_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_41_1) x_42_0 = 0; T_2_94_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_57_2 <= 0) x_60_1 = 0; T_1_95_1: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0) x_61_0 = 564096371; T_1_96_1: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0) x_61_1 = x_55_1; T_1_97_1: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0) x_62_0 = 1599044894; T_1_98_1: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0) x_62_1 = x_61_1; T_2_99_2: if (x_0_1 + x_52_1 > x_11_1 && x_0_1 != 0) x_0_2 = 0; T_2_100_2: if (x_52_1 < x_11_1) x_63_0 = 1090411019; T_2_101_2: if (x_52_1 < x_11_1) x_63_1 = 47086786778880; T_2_102_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_41_1 && 0 == x_12_2 + 1) x_12_3 = 1; T_2_103_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_41_1 && 1 == x_12_3) x_42_1 = 0; T_2_104_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 1 == x_12_3) x_43_0 = 699807139; T_2_105_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 1 == x_12_3) x_43_1 = 0; T_1_106_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_43_1 && 1 == x_12_3) x_40_1 = x_41_1; T_1_107_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_43_1 && 1 == x_12_3) x_20_4 = x_20_3 + x_40_1; T_1_108_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_43_1 && 1 == x_12_3) x_41_2 = -1*x_40_1 + x_41_1; T_1_109_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_41_2 <= 0 && 1 == x_12_3) x_44_0 = 0; T_1_110_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_41_2 <= 0 && 1 == x_12_3) x_12_4 = -1; T_1_111_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_41_2 <= 0) x_44_1 = 0; T_1_112_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_45_0 = 1035616174; T_1_113_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_45_1 = x_43_1; T_1_114_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_46_0 = 1080050032; T_1_115_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_46_1 = x_45_1; T_1_116_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_0_3 = 0; T_1_117_1: if (x_52_1 < x_11_1) x_64_0 = 1059938716; T_1_118_1: if (x_52_1 < x_11_1) x_64_1 = x_0_2 + x_52_1; T_1_119_1: if (x_52_1 < x_11_1) x_53_1 = 0; T_1_120_1: if (x_52_1 < x_11_1 && x_53_1 < x_51_1) x_65_0 = 1700369668; T_1_121_1: if (x_52_1 < x_11_1 && x_53_1 < x_51_1) x_65_1 = 47086786778880; T_2_122_2: if (x_52_1 < x_11_1) x_53_2 = 1 + x_53_1; T_2_123_2: if (x_52_1 < x_11_1 && x_53_2 < x_51_1) x_65_2 = 47086786778880; T_2_124_2: if (x_52_1 < x_11_1) x_53_3 = 1 + x_53_2; T_2_125_2: if (x_52_1 < x_11_1) x_66_0 = 282422485; T_2_126_2: if (x_52_1 < x_11_1) x_66_1 = 47086786778880; T_2_127_2: if (x_36_1 < x_11_1) x_47_0 = 1485577752; T_2_128_2: if (x_36_1 < x_11_1) x_47_1 = 47086784677632; T_2_129_2: if (x_36_1 < x_11_1) x_48_0 = 536848037; T_2_130_2: if (x_36_1 < x_11_1) x_48_1 = x_0_3 + x_36_1; T_2_131_2: if (x_36_1 < x_11_1) x_37_1 = 0; T_1_132_1: if (x_36_1 < x_11_1 && x_37_1 < x_35_1) x_49_0 = 1095536948; T_1_133_1: if (x_36_1 < x_11_1 && x_37_1 < x_35_1) x_49_1 = 47086784677632; T_1_134_1: if (x_36_1 < x_11_1) x_37_2 = 1 + x_37_1; T_1_135_1: if (x_36_1 < x_11_1) x_50_0 = 1092054026; T_1_136_1: if (x_36_1 < x_11_1) x_50_1 = 47086784677632; T_1_137_1: if (x_52_1 < x_11_1) x_0_4 = x_0_3 + x_52_1; T_1_138_1: if (x_36_1 < x_11_1) x_0_5 = x_0_3 + x_36_1; T_1_139_1: if (x_52_1 < x_11_1) x_67_0 = 1253173599; T_1_140_1: if (x_52_1 < x_11_1) x_67_1 = 47086786778880; T_1_141_1: if (x_52_1 < x_11_1) x_68_0 = 45257227; T_1_142_1: if (x_52_1 < x_11_1) x_68_1 = 47086786778880; T_2_143_2: if (x_52_1 < x_11_1) assert(x_0_5 == x_64_1); }
the_stack_data/28264064.c
#include <stdlib.h> #include <stdbool.h> static void initArray(int* array, int size) { for(int i=0;i<size;i++){ array[i] = size-1-i; array[i] = i%2 == 0 ? array[i] : array[i]*-1; // interleaves positive and negative values } } // init two identical arrays with interleaved positive and negative values static void initArrays(int* array1, int* array2, int size) { initArray(array1, size); initArray(array2, size); } // check if all elemets in array1 are in array2 static bool checkArraysElements(int* array1, int* array2, int size) { bool usedIndexes[size]; bool flag = true; for(int i=0; i<size; i++) usedIndexes[i]=false; for(int i=0; i<size; i++) for(int j=0; j<size; j++) if(array1[i]==array2[j] && !usedIndexes[j]){ usedIndexes[j]=true; break; } for(int i=0; i<size; i++) if(!usedIndexes[i]){ flag = false; break; } return flag; } /* // test the checkArraysElements function void testCompareArraysFunc(void) { array2[0] = array1[size-1]; array2[size-1] = array1[0]; TEST_ASSERT_MESSAGE(checkArraysElements(),"Error in compareArray function"); } */ // check if array1 is in the correct order static bool isArrayInCorrectOrder(int* array1, int size){ for(int i=0; i<size-1; i++) if(array1[i]>array1[i+1]) return false; return true; }
the_stack_data/68889005.c
#include <stdio.h> #include <signal.h> #include <unistd.h> #include <stdlib.h> // Usage ./kill pid int main(int argc, char const *argv[]) { int i; if(strcmp(argv[1],"./kill")==0) { kill(atoi(argv[2]),SIGKILL); // close some tab } }
the_stack_data/161081143.c
int x, y; int main(void) { y = 1 + (x=1); return 0; }
the_stack_data/52489.c
/*--------------------------------------------------------------- * Motorola 68000 32 Bit emulator * * Copyright 1998-2001 Mike Coates, All rights reserved * Darren Olafson *--------------------------------------------------------------- * * Thanks to ... * * Neil Bradley (lots of optimisation help & ideas) * *--------------------------------------------------------------- * History (so we know what bugs have been fixed) * * 02.11.98 MJC - CMPM bug, overwriting first value * 04.11.98 MJC - Debug timing - same as C core * save PC on calls to C memory routines * 05.11.98 NS - Re-insert changes to make work on OS/2 * 06.11.98 MJC - Flags saved on ADDA commands * X set on ADD commands * 23.11.98 MJC - Alternate Memory Read/Write for non DOS ports * 24.11.98 CK - Add WIN32 specific stuff * 25.11.98 DEO - ABCD Size not initialised * 21.12.98 MJC - Change register saving on Memory Banking * 13.01.99 M/D - Change to new C core disassembler * 19.01.99 MJC - Proper? support for new Interrupt System * 17.02.99 MJC - TRACE68K define added * ABCD,SBCD not keeping Z flag * JMP, JSR for some EA combo's damaging flags * DIVU - Overflow not being set correctly * ASL/ASR - Flag Handling now correct * some minor optimisations * 13.03.99 DEO - Added new cycle timing * 24.03.99 MJC - TRACE68K define removed * NEW INTERRUPT SYSTEM only * interrupt check sped up (when not taken) * STOP checks for interrupt * 01.04.99 MJC - OS2 specifics added * MOVEM reference point moved * Data and Address register mode combined for :- * movecodes * dumpx * 04.05.99 MJC - Add Previous PC support to MOVE.B #X,XXXXXX.L (F1 Dream) * ABCD/SBCD could corrupt zero flag * DIVS/DIVU overflow should not update register * 22.05.99 MJC - Complete support of Previous PC on C calls * Some optional bits now selected by DEFINES * 27.05.99 MJC - Interrupt system changed * 28.05.99 MJC - Use DEFINES in more places * Interrupt check running one opcode when taken * 16.07.99 MJC - Reset - Preload next opcode / external call * 68010 commands almost complete * more compression on jump table (16k smaller) * Some optimising * shl reg,1 -> add reg,reg * or ecx,ecx:jz -> jecxz * 22.08.99 DEO - SBCD/ABCD sets N flag same as carry * 19.10.99 MJC - Change DOS memory routines * Change DOS Clobber flags (ESI no longer safe) * Save EAX around memory write where needed * bit commands optimised * 25.10.99 MJC - Was keeping masked register on read/write * if register was preserved over call * ESI assumed 'safe' again * 25.10.99 MJC - Bank ID moved to CPU context * 03.11.99 KENJO - VC++6.0 seems not to preserve EDI. Fixed "ABCD -(A0), -(A0)" crash / "roxr (A0)"-type shift crash * 13.11.99 KENJO - Fixed "NABC" * Now Win32 uses FASTCALL type call for interrupt callback * 09.02.00 MJC - Check CPU type before allowing 68010/68020 instructions * remove routines for 5 non existant opcodes * 05.03.00 MJC - not command decrement A7 by 1 for bytes * 10.03.00 MJC - as did btst,cmpm and nbcd * 22.03.00 MJC - Divide by zero should not decrement PC by 2 before push * Move memory banking into exception routine * 14.04.00 Dave - BTST missing Opcode * ASL.L > 31 shift * 20.04.00 MJC - TST.B Also missing A7 specific routine * - Extra Define A7ROUTINE to switch between having seperate * routines for +-(A7) address modes. * 24.06.00 MJC - ADDX/SUBX +-(A7) routines added. * TAS should not touch X flag * LSL/LSR EA not clearing V flag * CHK not all opcodes in jump table * Add define to mask status register * 04.07.00 MJC - Keep high byte of Program Counter on Bxx and Jxx * Fix flag handling on NEGX * Really fix ADDX/SUBX +-(A7) * PC could be set wrong after CHK.W instruction * DIVS/DIVU always clear C flag * ABCD/SBCD missing +-(A7) Routine * TAS missing +-(A7) Routine * Bitwise Static missing +-(A7) Routine * CMPM missing +-(A7) Routine * 30.09.00 DEO - added mull, divl, bfextu * added '020 addressing modes * fixed $6xff branching * 23.01.01 MJC - Spits out seperate code for 68000 & 68020 * allows seperate optimising! * 17.02.01 MJC - Support for encrypted PC relative fetch calls * 11.03.01 GUTI - change some cmp reg,0 and or reg,reg with test * 13.03.01 MJC - Single Icount for Asm & C cores * 16.05.01 ASG - use push/pop around mem calls instead of store to safe_REG * optimized a bit the 020 extension word decoder * removed lots of unnecessary code in branches *--------------------------------------------------------------- * Known Problems / Bugs * * 68000 * None - Let us know if you find any! * * 68010 * Instructions that are supervisor only as per 68000 spec. * move address space not implemented. * * 68020 * only long Bcc instruction implemented. *--------------------------------------------------------------- * Notes * * STALLCHECK should be defined for Pentium Class * undefined for P2/Celerons * * ALIGNMENT is normally 4, but seems faster on my P2 as 0 ! * *--------------------------------------------------------------- * * Future Changes * * 68020 instructions to be completed * assembler memory routines + * * and anything else that takes our fancy! *---------------------------------------------------------------*/ /* Specials - Switch what program allows/disallows */ #undef STALLCHECK /* Affects fetching of Opcode */ #undef SAVEPPC /* Save Previous PC (!!! FBA setting) */ #define ENCRYPTED /* PC relative = decrypted */ #define ASMBANK 10 /* Memory banking algorithm to use LVR - (bank size = 1 << ASMBANK (8 = 16)) */ #define A7ROUTINE /* Define to use separate routines for -(a7)/(a7)+ */ #define ALIGNMENT 4 /* Alignment to use for branches */ #undef MASKCCR /* Mask the status register to filter out unused bits */ #define KEEPHIGHPC /* Keep or Ignore bits 24-31 */ #define QUICKZERO /* selects XOR r,r or MOV r,0 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> /* New Disassembler */ char * codebuf; int DisOp; #define cpu_readmem24bew(addr) (0) #define cpu_readmem24bew_word(addr) (DisOp) #define MEMORY_H /* so memory.h will not be included... */ /* #include "d68k.c" */ #undef MEMORY_H #undef cpu_readmem24bew #undef cpu_readmem24bew_word /* * Defines used by Program * */ #define VERSION "0.30" #define TRUE -1 #define FALSE 0 #define EAX 0 #define EBX 1 #define ECX 2 #define EDX 3 #define ESI 4 #define PC ESI #define EDI 5 #define EBP 6 #define NORMAL 0 #define PCREL 1 #ifdef __ELF__ #define PREF "" #else #define PREF "_" #endif /* Register Location Offsets */ #define ICOUNT PREF "m68k_ICount" #define REG_DAT "R_D0" #define REG_DAT_EBX "[R_D0+ebx*4]" #define REG_ADD "R_A0" #define REG_A7 "R_A7" #define REG_USP "R_USP" #define REG_ISP "R_ISP" #define REG_SRH "R_SR_H" #define REG_CCR "R_CCR" #define REG_X "R_XC" #define REG_PC "R_PC" #define REG_IRQ "R_IRQ" #define REG_S "R_SR" #define REG_IRQ_CALLBACK "R_IRQ_CALLBACK" #define REG_RESET_CALLBACK "R_RESET_CALLBACK" /* 68010 Regs */ #define REG_VBR "R_VBR" #define REG_SFC "R_SFC" #define REG_DFC "R_DFC" #define FASTCALL_FIRST_REG "ecx" #define FASTCALL_SECOND_REG "edx" /* * Global Variables * */ FILE *fp = NULL; char *comptab = NULL; char *CPUtype = NULL; int CPU = 0; int FlagProcess = 0; int CheckInterrupt = 0; int ExternalIO = 0; int Opcount = 0; int TimingCycles = 0; int AddEACycles = 0; int AccessType = NORMAL; int ppro = 0; /* External register preservation */ #ifdef DOS /* Registers normally saved around C routines anyway */ /* GCC 2.9.1 (dos) seems to preserve EBX,EDI and EBP */ static char SavedRegs[] = "-B--SDB"; #elif defined(WIN32) /* visual C++, win32, says it preserves ebx, edi, esi, and ebp */ /* ---------- VC++ deosn't preserve EDI? (Kenjo, 110399) ---------- */ static char SavedRegs[] = "-B--S-B"; #else /* Assume nothing preserved */ static char SavedRegs[] = "-------"; #endif /* Jump Table */ int OpcodeArray[65536]; /* Lookup Arrays */ static char* regnameslong[] = { "EAX","EBX","ECX","EDX","ESI","EDI","EBP"}; static char* regnamesword[] = { "AX","BX","CX","DX", "SI", "DI", "BP"}; static char* regnamesshort[] = { "AL","BL","CL","DL"}; /*********************************/ /* Conversion / Utility Routines */ /*********************************/ /* Convert EA to Address Mode Number * * 0 Dn * 1 An * 2 (An) * 3 (An)+ * 4 -(An) * 5 x(An) * 6 x(An,xr.s) * 7 x.w * 8 x.l * 9 x(PC) * 10 x(PC,xr.s) * 11 #x,SR,CCR Read = Immediate, Write = SR or CCR * in order to read SR to AX, use READCCR * 12-15 INVALID * * 19 (A7)+ * 20 -(A7) * */ int EAtoAMN(int EA, int Way) { int Work; if (Way) { Work = (EA & 0x7); if (Work == 7) Work += ((EA & 0x38) >> 3); if (((Work == 3) || (Work == 4)) && (((EA & 0x38) >> 3) == 7)) { Work += 16; } } else { Work = (EA & 0x38) >> 3; if (Work == 7) Work += (EA & 7); if (((Work == 3) || (Work == 4)) && ((EA & 7) == 7)) { Work += 16; } } return Work; } /* * Generate Main or Sub label */ char *GenerateLabel(int ID,int Type) { static int LabID,LabNum; /* static char disasm[80]; char *dis = disasm; */ if (Type == 0) { CheckInterrupt=0; /* No need to check for Interrupts */ ExternalIO=0; /* Not left Assembler Yet */ TimingCycles=0; /* No timing info for this command */ AddEACycles=1; /* default to add in EA timing */ Opcount++; /* for screen display */ DisOp = ID; /* m68k_disassemble(dis,0); sprintf(codebuf, "OP%d_%4.4x:\t\t\t\t; %s", CPU,ID, dis); */ sprintf(codebuf, "OP%d_%4.4x:\t\t\t\t;", CPU,ID); LabID = ID; LabNum = 0; } else { LabNum++; sprintf(codebuf, "OP%d_%4.4x_%1x", CPU,LabID, LabNum); } return codebuf; } /* * Generate Alignment Line */ void Align(void) { fprintf(fp, "\t\t ALIGN %d\n\n",ALIGNMENT); } /* * Copy X into Carry * * There are several ways this could be done, this allows * us to easily change the way we are doing it! */ void CopyX(void) { /* Copy bit 0 from X flag store into Carry */ fprintf(fp, "\t\t bt dword [%s],0\n",REG_X); } /* * Immediate 3 bit data * * 0=8, anything else is itself * * Again, several ways to achieve this * * ECX contains data as 3 lowest bits * */ void ClearRegister(int regno) { #ifdef QUICKZERO fprintf(fp, "\t\t mov %s,0\n",regnameslong[regno]); #else fprintf(fp, "\t\t xor %s,%s\n",regnameslong[regno],regnameslong[regno]); #endif } void Immediate8(void) { /* This takes 3 cycles, 5 bytes, no memory reads */ fprintf(fp, "\t\t dec ecx ; Move range down\n"); fprintf(fp, "\t\t and ecx,byte 7 ; Mask out lower bits\n"); fprintf(fp, "\t\t inc ecx ; correct range\n"); /* This takes 2 cycles, 10 bytes but has a memory read */ /* I don't know timing for the mov command - assumed 1 */ #if 0 fprintf(fp, "\t\t and ecx,byte 7\n"); fprintf(fp, "\t\t mov ecx,[ImmTable+ECX*4]\n"); #endif } /* * This will check for bank changes before * resorting to calling the C bank select code * * Most of the time it does not change! * */ /* forward used by MemoryBanking */ void Exception(int Number, int BaseCode) ; void MemoryBanking(int BaseCode) { /* check for odd address */ fprintf(fp, "\t\t test esi, dword 1\n"); fprintf(fp, "\t\t jz near OP%d_%5.5x\n",CPU,BaseCode); /* trying to run at an odd address */ Exception(3,BaseCode); /* Keep Whole PC */ fprintf(fp, "OP%d_%5.5x:\n",CPU,BaseCode); /* ASG - always call to the changepc subroutine now, since the number of */ /* bits varies based on the memory model */ #ifdef KEEPHIGHPC fprintf(fp, "\t\t mov [FullPC],ESI\n"); #endif /* Mask to n bits */ fprintf(fp, "\t\t and esi,[%smem_amask]\n", PREF); #if 0 #ifdef KEEPHIGHPC fprintf(fp, "\t\t mov [FullPC],ESI\n"); #endif /* Mask to 24 bits */ // fprintf(fp, "\t\t and esi,0ffffffh\n"); #ifdef ASMBANK /* Assembler bank switch */ fprintf(fp, "\t\t mov eax,esi\n"); /* LVR - use a variable bank size */ fprintf(fp, "\t\t shr eax," ASMBANK "\n"); fprintf(fp, "\t\t cmp [asmbank],eax\n"); fprintf(fp, "\t\t je OP%d_%5.5x_Bank\n",CPU,BaseCode); fprintf(fp, "\t\t mov [asmbank],eax\n"); #else /* This code is same as macro used by C core */ fprintf(fp, "\t\t mov ecx,esi\n"); fprintf(fp, "\t\t mov ebx,[_cur_mrhard]\n"); fprintf(fp, "\t\t shr ecx,9\n"); fprintf(fp, "\t\t mov al,byte [_opcode_entry]\n"); fprintf(fp, "\t\t cmp al,[ecx+ebx]\n"); fprintf(fp, "\t\t je OP%d_%5.5x_Bank\n",CPU,BaseCode); #endif #endif /* Call Banking Routine */ if (SavedRegs[ESI] == '-') { fprintf(fp, "\t\t mov [%s],ESI\n",REG_PC); } if (SavedRegs[EDX] == '-') { fprintf(fp, "\t\t mov [%s],edx\n",REG_CCR); } #ifdef FASTCALL fprintf(fp, "\t\t mov %s,esi\n",FASTCALL_FIRST_REG); #else fprintf(fp, "\t\t push esi\n"); #endif fprintf(fp, "\t\t call [%sa68k_memory_intf+28]\n", PREF); #ifndef FASTCALL fprintf(fp, "\t\t lea esp,[esp+4]\n"); #endif if (SavedRegs[EDX] == '-') { fprintf(fp, "\t\t mov edx,[%s]\n",REG_CCR); } if (SavedRegs[ESI] == '-') { fprintf(fp, "\t\t mov esi,[%s]\n",REG_PC); } /* Update our copy */ fprintf(fp, "\t\t mov ebp,dword [%sOP_ROM]\n", PREF); fprintf(fp, "OP%d_%5.5x_Bank:\n",CPU,BaseCode); } /* * Update Previous PC value * */ void SavePreviousPC(void) { #ifdef SAVEPPC fprintf(fp, "\t\t mov [R_PPC],esi\t\t\t ; Keep Previous PC\n"); #endif } /* * Complete Opcode handling * * Any tidying up, end code * */ void Completed(void) { /* Flag Processing to be finished off ? */ AccessType = NORMAL; /* Use assembler timing routines */ if (TimingCycles != 0) { if (TimingCycles > 127) fprintf(fp, "\t\t sub dword [%s],%d\n",ICOUNT,TimingCycles); else { if (TimingCycles != -1) fprintf(fp, "\t\t sub dword [%s],byte %d\n",ICOUNT,TimingCycles); } if (FlagProcess > 0) fprintf(fp, "\t\t pop EDX\n"); if (FlagProcess == 2) fprintf(fp, "\t\t mov [%s],edx\n",REG_X); fprintf(fp, "\t\t js near MainExit\n\n"); } else { fprintf(fp, "\t\t test dword [%s],0xffffffff\n",ICOUNT); if (FlagProcess > 0) fprintf(fp, "\t\t pop EDX\n"); if (FlagProcess == 2) fprintf(fp, "\t\t mov [%s],edx\n",REG_X); fprintf(fp, "\t\t jle near MainExit\n\n"); } FlagProcess = 0; #ifdef MAME_DEBUG /* Check for Debug Active */ fprintf(fp, "\n\t\t test byte [%smame_debug],byte 0xff\n", PREF); fprintf(fp, "\t\t jnz near MainExit\n\n"); #endif #ifdef FBA_DEBUG fprintf(fp, "\n\t\t test byte [%smame_debug],byte 0xff\n", PREF); fprintf(fp, "\t\t jns near .NoDebug\n"); fprintf(fp, "\t\t call near FBADebugActive\n\n"); fprintf(fp, ".NoDebug\n"); #endif if (CheckInterrupt) { fprintf(fp,"; Check for Interrupt waiting\n\n"); fprintf(fp,"\t\t test byte [%s],07H\n",REG_IRQ); fprintf(fp,"\t\t jne near interrupt\n\n"); } if(CPU==2) { /* 32 bit memory version */ fprintf(fp, "\t\t mov eax,2\n"); /* ASG */ fprintf(fp, "\t\t xor eax,esi\n"); /* ASG */ #ifdef STALLCHECK ClearRegister(ECX); fprintf(fp, "\t\t mov cx,[eax+ebp]\n"); #else fprintf(fp, "\t\t movzx ecx,word [eax+ebp]\n"); #endif } else { /* 16 bit memory */ #ifdef STALLCHECK ClearRegister(ECX); fprintf(fp, "\t\t mov cx,[esi+ebp]\n"); #else fprintf(fp, "\t\t movzx ecx,word [esi+ebp]\n"); #endif } fprintf(fp, "\t\t jmp [%s_OPCODETABLE+ecx*4]\n\n", CPUtype); } /* * Flag Routines * * Size = B,W or L * Sreg = Register to Test * TestReg = Need to test register (false if flags already set up) * SetX = if C needs to be copied across to X register * Delayed = Delays final processing to end of routine (Completed()) * */ void TestFlags(char Size,int Sreg) { char* Regname=""; switch (Size) { case 66: Regname = regnamesshort[Sreg]; break; case 87: Regname = regnamesword[Sreg]; break; case 76: Regname = regnameslong[Sreg]; break; } /* Test does not update register */ /* so cannot generate partial stall */ fprintf(fp, "\t\t test %s,%s\n",Regname,Regname); } void SetFlags(char Size,int Sreg,int Testreg,int SetX,int Delayed) { if (Testreg) TestFlags(Size,Sreg); fprintf(fp, "\t\t pushfd\n"); if (Delayed) { /* Rest of code done by Completed routine */ if (SetX) FlagProcess = 2; else FlagProcess = 1; } else { fprintf(fp, "\t\t pop EDX\n"); if (SetX) fprintf(fp, "\t\t mov [%s],edx\n",REG_X); } } /******************/ /* Check CPU Type */ /******************/ void CheckCPUtype(int Minimum) { if(CPU==2) { /* Only check for > 020 */ if(Minimum>2) { fprintf(fp, "\t\t mov eax,[CPUversion]\n"); fprintf(fp, "\t\t cmp al,%d\n",Minimum); fprintf(fp, "\t\t jb near ILLEGAL\n\n"); } } else { fprintf(fp, "\t\t mov eax,[CPUversion]\n"); if (Minimum == 1) { fprintf(fp, "\t\t test eax,eax\n"); fprintf(fp, "\t\t jz near ILLEGAL\n\n"); } else { fprintf(fp, "\t\t cmp al,%d\n",Minimum); fprintf(fp, "\t\t jb near ILLEGAL\n\n"); } } } /************************************/ /* Pre-increment and Post-Decrement */ /************************************/ void IncrementEDI(int Size,int Rreg) { switch (Size) { case 66: #ifdef A7ROUTINE /* Always does Byte Increment - A7 uses special routine */ fprintf(fp, "\t\t inc dword [%s+%s*4]\n",REG_ADD,regnameslong[Rreg]); #else /* A7 uses same routines, so inc by 2 if A7 */ fprintf(fp, "\t\t cmp %s,7\n",regnamesshort[Rreg]); fprintf(fp, "\t\t cmc\n"); fprintf(fp, "\t\t adc dword [%s+%s*4],byte 1\n",REG_ADD,regnameslong[Rreg]); #endif break; case 87: fprintf(fp, "\t\t add dword [%s+%s*4],byte 2\n",REG_ADD,regnameslong[Rreg]); break; case 76: fprintf(fp, "\t\t add dword [%s+%s*4],byte 4\n",REG_ADD,regnameslong[Rreg]); break; } } void DecrementEDI(int Size,int Rreg) { switch (Size) { case 66: #ifdef A7ROUTINE /* Always does Byte Increment - A7 uses special routine */ fprintf(fp, "\t\t dec EDI\n"); #else /* A7 uses same routines, so dec by 2 if A7 */ fprintf(fp, "\t\t cmp %s,7\n",regnamesshort[Rreg]); fprintf(fp, "\t\t cmc\n"); fprintf(fp, "\t\t sbb dword edi,byte 1\n"); #endif break; case 87: fprintf(fp, "\t\t sub EDI,byte 2\n"); break; case 76: fprintf(fp, "\t\t sub EDI,byte 4\n"); break; } } /* * Generate an exception * * if Number = -1 then assume value in AL already * code must continue running afterwards * */ void Exception(int Number, int BaseCode) { if (Number > -1) { fprintf(fp, "\t\t sub esi,byte 2\n"); fprintf(fp, "\t\t mov al,%d\n",Number); } fprintf(fp, "\t\t call Exception\n\n"); if (Number > -1) Completed(); } /********************/ /* Address Routines */ /********************/ /* * Decode Intel flags into AX as SR register * * Wreg = spare register to use (must not be EAX or EDX) */ void ReadCCR(char Size, int Wreg) { fprintf(fp, "\t\t mov eax,edx\n"); fprintf(fp, "\t\t mov ah,byte [%s]\n",REG_X); /* Partial stall so .. switch to new bit of processing */ fprintf(fp, "\t\t mov %s,edx\n",regnameslong[Wreg]); fprintf(fp, "\t\t and %s,byte 1\n",regnameslong[Wreg]); /* Finish what we started */ fprintf(fp, "\t\t shr eax,4\n"); fprintf(fp, "\t\t and eax,byte 01Ch \t\t; X, N & Z\n\n"); /* and complete second task */ fprintf(fp, "\t\t or eax,%s \t\t\t\t; C\n\n",regnameslong[Wreg]); /* and Finally */ fprintf(fp, "\t\t mov %s,edx\n",regnameslong[Wreg]); fprintf(fp, "\t\t shr %s,10\n",regnameslong[Wreg]); fprintf(fp, "\t\t and %s,byte 2\n",regnameslong[Wreg]); fprintf(fp, "\t\t or eax,%s\t\t\t\t; O\n\n",regnameslong[Wreg]); if (Size == 'W') { fprintf(fp, "\t\t mov ah,byte [%s] \t; T, S & I\n\n",REG_SRH); #ifdef MASKCCR fprintf(fp, "\t\t and ax,0A71Fh\t; Mask unused bits\n"); #endif } } /* * Convert SR into Intel flags * * Also handles change of mode from Supervisor to User * * n.b. This is also called by EffectiveAddressWrite */ void WriteCCR(char Size) { if (Size == 'W') { /* Did we change from Supervisor to User mode ? */ char *Label = GenerateLabel(0,1); fprintf(fp, "\t\t test ah,20h \t\t\t; User Mode ?\n"); fprintf(fp, "\t\t jne short %s\n\n",Label); /* Mode Switch - Update A7 */ fprintf(fp, "\t\t mov edx,[%s]\n",REG_A7); fprintf(fp, "\t\t mov [%s],edx\n",REG_ISP); fprintf(fp, "\t\t mov edx,[%s]\n",REG_USP); fprintf(fp, "\t\t mov [%s],edx\n",REG_A7); fprintf(fp, "%s:\n",Label); fprintf(fp, "\t\t mov byte [%s],ah \t;T, S & I\n",REG_SRH); /* Mask may now allow Interrupt */ CheckInterrupt += 1; } /* Flags */ fprintf(fp, "\t\t and eax,byte 1Fh\n"); fprintf(fp, "\t\t mov edx,[IntelFlag+eax*4]\n"); fprintf(fp, "\t\t mov [%s],dh\n",REG_X); fprintf(fp, "\t\t and edx,0EFFh\n"); } /* * Interface to Mame memory commands * * Flags = "ABCDSDB" - set to '-' if not required to preserve * (order EAX,EBX,ECX,EDX,ESI,EDI,EBP) * * AReg = Register containing Address * * Mask 0 : No Masking * 1 : Mask top byte, but preserve register * 2 : Mask top byte, preserve masked register */ void Memory_Read(char Size,int AReg,char *Flags,int Mask) { ExternalIO = 1; /* Save PC */ fprintf(fp, "\t\t mov [%s],ESI\n",REG_PC); /* Check for special mask condition */ /* ASG - no longer need to mask addresses here */ /* if (Mask == 2) fprintf(fp, "\t\t and %s,0FFFFFFh\n",regnameslong[AReg]);*/ /* Check to see if registers need saving */ if ((Flags[EDX] != '-') && (SavedRegs[EDX] == '-')) { fprintf(fp, "\t\t mov [%s],edx\n",REG_CCR); } if ((Flags[EBX] != '-') && (SavedRegs[EBX] == '-')) { fprintf(fp, "\t\t push EBX\n"); } if ((Flags[ECX] != '-') && (SavedRegs[ECX] == '-')) { fprintf(fp, "\t\t push ECX\n"); } if ((Flags[EDI] != '-') && (SavedRegs[EDI] == '-')) { fprintf(fp, "\t\t push EDI\n"); } /* Sort Address out */ #ifdef FASTCALL fprintf(fp, "\t\t mov %s,%s\n",FASTCALL_FIRST_REG,regnameslong[AReg]); /* ASG - no longer need to mask addresses here */ /* if (Mask == 1) fprintf(fp, "\t\t and %s,0FFFFFFh\n",FASTCALL_FIRST_REG);*/ #else if (Mask == 1) { if ((Flags[AReg] != '-') && (SavedRegs[AReg] != '-')) { /* Don't trash a wanted safe register */ fprintf(fp, "\t\t mov EAX,%s\n",regnameslong[AReg]); /* ASG - no longer need to mask addresses here */ /* fprintf(fp, "\t\t and EAX,0FFFFFFh\n");*/ fprintf(fp, "\t\t push EAX\n"); } else { /* ASG - no longer need to mask addresses here */ /* fprintf(fp, "\t\t and %s,0FFFFFFh\n",regnameslong[AReg]);*/ fprintf(fp, "\t\t push %s\n",regnameslong[AReg]); } } else fprintf(fp, "\t\t push %s\n",regnameslong[AReg]); #endif /* Call Mame memory routine */ /* ASG - changed these to call through the function pointers */ #ifdef ENCRYPTED switch (AccessType) { case NORMAL : switch (Size) { case 66 : fprintf(fp, "\t\t call [%sa68k_memory_intf+4]\n", PREF); break; case 87 : fprintf(fp, "\t\t call [%sa68k_memory_intf+8]\n", PREF); break; case 76 : fprintf(fp, "\t\t call [%sa68k_memory_intf+12]\n", PREF); break; } break; case PCREL : switch (Size) { case 66 : fprintf(fp, "\t\t call [%sa68k_memory_intf+32]\n", PREF); break; case 87 : fprintf(fp, "\t\t call [%sa68k_memory_intf+36]\n", PREF); break; case 76 : fprintf(fp, "\t\t call [%sa68k_memory_intf+40]\n", PREF); break; } break; } // AccessType = NORMAL; #else switch (Size) { case 66 : fprintf(fp, "\t\t call [%sa68k_memory_intf+4]\n", PREF); break; case 87 : fprintf(fp, "\t\t call [%sa68k_memory_intf+8]\n", PREF); break; case 76 : fprintf(fp, "\t\t call [%sa68k_memory_intf+12]\n", PREF); break; } #endif /* Correct Stack */ #ifndef FASTCALL fprintf(fp, "\t\t lea esp,[esp+4]\n"); #endif /* Restore registers */ /* Check to see if registers need restoring */ if ((Flags[EDI] != '-') && (SavedRegs[EDI] == '-')) { fprintf(fp, "\t\t pop EDI\n"); } if ((Flags[ECX] != '-') && (SavedRegs[ECX] == '-')) { fprintf(fp, "\t\t pop ECX\n"); } if ((Flags[EBX] != '-') && (SavedRegs[EBX] == '-')) { fprintf(fp, "\t\t pop EBX\n"); } if ((Flags[ESI] != '-') && (SavedRegs[ESI] == '-')) { fprintf(fp, "\t\t mov ESI,[%s]\n",REG_PC); } if ((Flags[EDX] != '-') && (SavedRegs[EDX] == '-')) { fprintf(fp, "\t\t mov EDX,[%s]\n",REG_CCR); } if ((Flags[EBP] != '-') && (SavedRegs[EBP] == '-')) { fprintf(fp, "\t\t mov ebp,dword [%sOP_ROM]\n", PREF); } } void Memory_Write(char Size,int AReg,int DReg,char *Flags,int Mask) { ExternalIO = 1; /* Save PC */ fprintf(fp, "\t\t mov [%s],ESI\n",REG_PC); /* Check for special mask condition */ /* ASG - no longer need to mask addresses here */ /* if (Mask == 2) fprintf(fp, "\t\t and %s,0FFFFFFh\n",regnameslong[AReg]);*/ /* Check to see if registers need saving */ if ((Flags[EDX] != '-') && (SavedRegs[EDX] == '-')) { fprintf(fp, "\t\t mov [%s],edx\n",REG_CCR); } if ((Flags[EAX] != '-') && (SavedRegs[EAX] == '-')) { fprintf(fp, "\t\t push EAX\n"); } if ((Flags[EBX] != '-') && (SavedRegs[EBX] == '-')) { fprintf(fp, "\t\t push EBX\n"); } if ((Flags[ECX] != '-') && (SavedRegs[ECX] == '-')) { fprintf(fp, "\t\t push ECX\n"); } if ((Flags[EDI] != '-') && (SavedRegs[EDI] == '-')) { fprintf(fp, "\t\t push EDI\n"); } #ifdef FASTCALL fprintf(fp, "\t\t mov %s,%s\n",FASTCALL_SECOND_REG,regnameslong[DReg]); fprintf(fp, "\t\t mov %s,%s\n",FASTCALL_FIRST_REG,regnameslong[AReg]); /* ASG - no longer need to mask addresses here */ /* if (Mask == 1) fprintf(fp, "\t\t and %s,0FFFFFFh\n",FASTCALL_FIRST_REG);*/ #else fprintf(fp, "\t\t push %s\n",regnameslong[DReg]); if (Mask == 1) { if ((Flags[AReg] != '-') && (SavedRegs[AReg] != '-')) { /* Don't trash a wanted safe register */ fprintf(fp, "\t\t mov EAX,%s\n",regnameslong[AReg]); /* ASG - no longer need to mask addresses here */ /* fprintf(fp, "\t\t and EAX,0FFFFFFh\n");*/ fprintf(fp, "\t\t push EAX\n"); } else { /* ASG - no longer need to mask addresses here */ /* fprintf(fp, "\t\t and %s,0FFFFFFh\n",regnameslong[AReg]);*/ fprintf(fp, "\t\t push %s\n",regnameslong[AReg]); } } else fprintf(fp, "\t\t push %s\n",regnameslong[AReg]); #endif /* Call Mame Routine */ /* ASG - changed these to call through the function pointers */ switch (Size) { case 66 : fprintf(fp, "\t\t call [%sa68k_memory_intf+16]\n", PREF); break; case 87 : fprintf(fp, "\t\t call [%sa68k_memory_intf+20]\n", PREF); break; case 76 : fprintf(fp, "\t\t call [%sa68k_memory_intf+24]\n", PREF); break; } /* Correct Stack */ #ifndef FASTCALL fprintf(fp, "\t\t lea esp,[esp+8]\n"); #endif /* Restore registers */ /* Check to see if registers need restoring */ if ((Flags[EDI] != '-') && (SavedRegs[EDI] == '-')) { fprintf(fp, "\t\t pop EDI\n"); } if ((Flags[ECX] != '-') && (SavedRegs[ECX] == '-')) { fprintf(fp, "\t\t pop ECX\n"); } if ((Flags[EBX] != '-') && (SavedRegs[EBX] == '-')) { fprintf(fp, "\t\t pop EBX\n"); } if ((Flags[EAX] != '-') && (SavedRegs[EAX] == '-')) { fprintf(fp, "\t\t pop EAX\n"); } if ((Flags[EDX] != '-') && (SavedRegs[EDX] == '-')) { fprintf(fp, "\t\t mov EDX,[%s]\n",REG_CCR); } if ((Flags[ESI] != '-') && (SavedRegs[ESI] == '-')) { fprintf(fp, "\t\t mov ESI,[%s]\n",REG_PC); } if ((Flags[EBP] != '-') && (SavedRegs[EBP] == '-')) { fprintf(fp, "\t\t mov ebp,dword [%sOP_ROM]\n", PREF); } } /* * Fetch data from Code area * * Dreg = Destination Register * Extend = Sign Extend Word to Long * */ void Memory_Fetch(char Size,int Dreg,int Extend) { static int loopcount=0; /* Always goes via OP_ROM */ if(CPU!=2) { /* 16 Bit version */ if ((Extend == TRUE) & (Size == 'W')) fprintf(fp, "\t\t movsx %s,word [esi+ebp]\n",regnameslong[Dreg]); else if (Size == 'W') fprintf(fp, "\t\t movzx %s,word [esi+ebp]\n",regnameslong[Dreg]); else fprintf(fp, "\t\t mov %s,dword [esi+ebp]\n",regnameslong[Dreg]); if (Size == 'L') fprintf(fp, "\t\t rol %s,16\n",regnameslong[Dreg]); } else { /* 32 Bit version */ if (Size == 'W') { fprintf(fp, "\t\t mov %s,esi\n",regnameslong[Dreg]); fprintf(fp, "\t\t xor %s,byte 2\n",regnameslong[Dreg]); if (Extend == TRUE) fprintf(fp, "\t\t movsx %s,word [%s+ebp]\n",regnameslong[Dreg],regnameslong[Dreg]); else fprintf(fp, "\t\t movzx %s,word [%s+ebp]\n",regnameslong[Dreg],regnameslong[Dreg]); } else { // if address is exact multiple of 4, long read will work // otherwise we need to get words address-2 and address+4 // Always read long fprintf(fp, "\t\t test esi,2\n"); if (!ppro) { fprintf(fp, "\t\t mov %s,dword [esi+ebp]\n",regnameslong[Dreg]); // OK ? fprintf(fp, "\t\t jz short FL%3.3d\n",loopcount+1); // no, so get high word fprintf(fp, "\t\t mov %s,dword [esi+ebp-4]\n",regnameslong[Dreg]); // and get low word fprintf(fp, "\t\t mov %s,word [esi+ebp+4]\n",regnamesword[Dreg]); fprintf(fp, "FL%3.3d:\n",++loopcount); } else { fprintf(fp, "\t\t cmovnz %s,dword [esi+ebp-4]\n",regnameslong[Dreg]); fprintf(fp, "\t\t cmovz %s,dword [esi+ebp]\n",regnameslong[Dreg]); fprintf(fp, "\t\t cmovnz %s,word [esi+ebp+4]\n",regnamesword[Dreg]); } } } } /**********************/ /* Push PC onto Stack */ /**********************/ void PushPC(int Wreg,int Wreg2,char *Flags, int Mask) { /* Wreg2 is only used when high byte is kept */ /* If it is EBP then the register is restored */ fprintf(fp, "\t\t mov %s,[%s]\t ; Push onto Stack\n",regnameslong[Wreg],REG_A7); fprintf(fp, "\t\t sub %s,byte 4\n",regnameslong[Wreg]); fprintf(fp, "\t\t mov [%s],%s\n",REG_A7,regnameslong[Wreg]); #ifndef KEEPHIGHPC Memory_Write('L',Wreg,ESI,Flags,Mask); #else fprintf(fp, "\t\t mov %s,[FullPC]\n",regnameslong[Wreg2]); fprintf(fp, "\t\t and %s,0xff000000\n",regnameslong[Wreg2]); fprintf(fp, "\t\t or %s,ESI\n",regnameslong[Wreg2]); Memory_Write('L',Wreg,Wreg2,Flags,Mask); if (Wreg2 == EBP) { fprintf(fp, "\t\t mov ebp,dword [%sOP_ROM]\n", PREF); } #endif } void ExtensionDecode(int SaveEDX) { char *Label = GenerateLabel(0,1); if (SaveEDX) fprintf(fp, "\t\t push edx\n"); Memory_Fetch('W',EAX,FALSE); fprintf(fp, "\t\t add esi,byte 2\n"); if(CPU!=2) { /* 68000 Extension */ fprintf(fp, "\t\t mov edx,eax\n"); fprintf(fp, "\t\t shr eax,12\n"); fprintf(fp, "\t\t test edx,0x0800\n"); fprintf(fp, "\t\t mov eax,[%s+eax*4]\n",REG_DAT); fprintf(fp, "\t\t jnz short %s\n",Label); fprintf(fp, "\t\t cwde\n"); fprintf(fp, "%s:\n",Label); fprintf(fp, "\t\t lea edi,[edi+eax]\n"); fprintf(fp, "\t\t movsx edx,dl\n"); fprintf(fp, "\t\t lea edi,[edi+edx]\n"); } else { /* 68020 Extension */ // eax holds scaled index // might be faster just to push all regs fprintf(fp, "\t\t push ebx\n"); fprintf(fp, "\t\t push ecx\n"); // copies for later use fprintf(fp, "\t\t mov ecx,eax\n"); fprintf(fp, "\t\t mov edx,eax\n"); // check E bit to see if displacement or full format fprintf(fp, "\t\t test edx,0x0100\n"); fprintf(fp, "\t\t jz short %s_a\n",Label); // full mode so check IS (index supress) fprintf(fp, "\t\t test edx,0x0040\n"); fprintf(fp, "\t\t jz short %s_b\n",Label); // set index to 0, it's not added ClearRegister(EAX); fprintf(fp, "\t\t jmp short %s_d\n",Label); // near // add displacement fprintf(fp, "%s_a:\n",Label); fprintf(fp, "\t\t movsx eax,al\n"); fprintf(fp, "\t\t lea edi,[edi+eax]\n"); fprintf(fp, "%s_b:\n",Label); // calc index always scale (68k will scale by 1) fprintf(fp, "\t\t mov eax,edx\n"); fprintf(fp, "\t\t shr eax,12\n"); fprintf(fp, "\t\t test edx,0x0800\n"); fprintf(fp, "\t\t mov eax,[%s+eax*4]\n",REG_DAT); fprintf(fp, "\t\t jnz short %s_c\n",Label); fprintf(fp, "\t\t cwde\n"); fprintf(fp, "%s_c:\n",Label); fprintf(fp, "\t\t shr ecx,byte 9\n"); fprintf(fp, "\t\t and ecx,byte 3\n"); fprintf(fp, "\t\t shl eax,cl\n"); // if brief mode we can add index and exit fprintf(fp, "\t\t test edx,0x0100\n"); fprintf(fp, "\t\t jz near %s_i2\n",Label); fprintf(fp, "%s_d:\n",Label); // check BS (base supress) // if BS is 1 then set edi to 0 fprintf(fp, "\t\t test edx,0x0080\n"); fprintf(fp, "\t\t jz short %s_4a\n",Label); ClearRegister(EDI); // if null displacement skip over fprintf(fp, "%s_4a:\n",Label); fprintf(fp, "\t\t test edx,0x0020\n"); fprintf(fp, "\t\t jz short %s_f\n",Label); // **** calc base displacement **** // is it long fprintf(fp, "\t\t test edx,0x0010\n"); fprintf(fp, "\t\t jz short %s_e\n",Label); // fetch long base Memory_Fetch('L',EBX,FALSE); fprintf(fp, "\t\t lea edi,[edi+ebx]\n"); fprintf(fp, "\t\t add esi,byte 4\n"); fprintf(fp, "\t\t jmp short %s_f\n",Label); // fetch word base fprintf(fp, "%s_e:\n",Label); Memory_Fetch('W',EBX,TRUE); fprintf(fp, "\t\t lea edi,[edi+ebx]\n"); fprintf(fp, "\t\t add esi,byte 2\n"); // **** indirect? **** fprintf(fp, "%s_f:\n",Label); fprintf(fp, "\t\t test edx,0x0003\n"); fprintf(fp, "\t\t jz near %s_7a\n",Label); // pre or post indirect fprintf(fp, "\t\t test edx,0x0004\n"); fprintf(fp, "\t\t jnz short %s_g\n",Label); // do pre fprintf(fp, "\t\t lea edi,[edi+eax]\n"); Memory_Read('L',EDI,"ABCDSDB",2); fprintf(fp, "\t\t mov edi,eax\n"); fprintf(fp, "\t\t jmp short %s_h\n",Label); // do post fprintf(fp, "%s_g:\n",Label); fprintf(fp, "\t\t push eax\n"); Memory_Read('L',EDI,"-B-DS-B",2); fprintf(fp, "\t\t pop edi\n"); fprintf(fp, "%s_7a:\n",Label); fprintf(fp, "\t\t lea edi,[edi+eax]\n"); // **** outer displacement **** // if null displacement skip over fprintf(fp, "%s_h:\n",Label); fprintf(fp, "\t\t test edx,0x0002\n"); fprintf(fp, "\t\t jz short %s_j\n",Label); // word or long? fprintf(fp, "\t\t test edx,0x0001\n"); fprintf(fp, "\t\t jz short %s_i\n",Label); // fetch long Memory_Fetch('L',EAX,FALSE); fprintf(fp, "\t\t add esi,byte 4\n"); fprintf(fp, "\t\t jmp short %s_i2\n",Label); // fetch word fprintf(fp, "%s_i:\n",Label); Memory_Fetch('W',EAX,TRUE); fprintf(fp, "\t\t add esi,byte 2\n"); fprintf(fp, "%s_i2:\n",Label); fprintf(fp, "\t\t lea edi,[edi+eax]\n"); // **** exit **** fprintf(fp, "%s_j:\n",Label); fprintf(fp, "\t\t pop ecx\n"); fprintf(fp, "\t\t pop ebx\n"); } if (SaveEDX) fprintf(fp, "\t\t pop edx\n"); } /* Calculate Effective Address - Return address in EDI * * mode = Effective Address from Instruction * Size = Byte,Word or Long * Rreg = Register with Register Number in * * Only for modes 2 - 10 (5-10 clobber EAX) */ void EffectiveAddressCalculate(int mode,char Size,int Rreg,int SaveEDX) { /* timing */ if ((TimingCycles > 0) && (AddEACycles!=0)) { switch (mode) { case 2: /* (An) */ case 3: /* (An)+ */ case 11: /* #x,SR,CCR */ case 19: /* (A7)+ */ TimingCycles += 4 ; break ; case 4: /* -(An) */ case 20: /* -(A7) */ TimingCycles += (CPU==2) ? 5 : 6 ; break ; case 5: /* x(An) */ case 9: /* x(PC) */ TimingCycles += (CPU==2) ? 5 : 8 ; break ; case 7: /* x.w */ TimingCycles += (CPU==2) ? 4 : 8 ; break ; case 6: /* x(An,xr.s) */ case 10: /* x(PC,xr.s) */ TimingCycles += (CPU==2) ? 7 : 10 ; break ; case 8: /* x.l */ TimingCycles += (CPU==2) ? 4 : 12 ; break ; } /* long w/r adds 4 cycles */ if ((mode>1) && (Size == 'L') && (CPU != 2)) TimingCycles += 4 ; } AccessType = NORMAL; switch (mode) { case 2: fprintf(fp, "\t\t mov EDI,[%s+%s*4]\n",REG_ADD,regnameslong[Rreg]); break; case 3: fprintf(fp, "\t\t mov EDI,[%s+%s*4]\n",REG_ADD,regnameslong[Rreg]); IncrementEDI(Size,Rreg); break; case 4: fprintf(fp, "\t\t mov EDI,[%s+%s*4]\n",REG_ADD,regnameslong[Rreg]); DecrementEDI(Size,Rreg); fprintf(fp, "\t\t mov [%s+%s*4],EDI\n",REG_ADD,regnameslong[Rreg]); break; case 5: Memory_Fetch('W',EAX,TRUE); fprintf(fp, "\t\t mov EDI,[%s+%s*4]\n",REG_ADD,regnameslong[Rreg]); fprintf(fp, "\t\t add esi,byte 2\n"); fprintf(fp, "\t\t add edi,eax\n"); break; case 6: /* Get Address register Value */ fprintf(fp, "\t\t mov EDI,[%s+%s*4]\n",REG_ADD,regnameslong[Rreg]); /* Add Extension Details */ ExtensionDecode(SaveEDX); break; case 7: /* Get Word */ Memory_Fetch('W',EDI,TRUE); // fprintf(fp, "\t\t movsx edi,di\n"); fprintf(fp, "\t\t add esi,byte 2\n"); break; case 8: /* Get Long */ Memory_Fetch('L',EDI,FALSE); fprintf(fp, "\t\t add esi,byte 4\n"); break; case 9: AccessType = PCREL; Memory_Fetch('W',EAX,TRUE); // fprintf(fp, "\t\t movsx eax,ax\n"); fprintf(fp, "\t\t mov EDI,ESI ; Get PC\n"); fprintf(fp, "\t\t add esi,byte 2\n"); fprintf(fp, "\t\t add edi,eax ; Add Offset to PC\n"); break; case 10: AccessType = PCREL; /* Get PC */ fprintf(fp, "\t\t mov edi,esi ; Get PC\n"); /* Add Extension Details */ ExtensionDecode(SaveEDX); break; case 19: /* (A7)+ */ fprintf(fp, "\t\t mov edi,[%s] ; Get A7\n",REG_A7); fprintf(fp, "\t\t add dword [%s],byte 2\n",REG_A7); break; case 20: /* -(A7) */ fprintf(fp, "\t\t mov edi,[%s] ; Get A7\n",REG_A7); fprintf(fp, "\t\t sub edi,byte 2\n"); fprintf(fp, "\t\t mov [%s],edi\n",REG_A7); break; } } /* Read from Effective Address * * mode = Effective Address from Instruction * Size = Byte,Word or Long * Rreg = Register with Register Number in * Flag = Registers to preserve (EDX is handled by SaveEDX) * * Return * Dreg = Register to return result in (EAX is usually most efficient) * (modes 5 to 10) EDI = Address of data read (masked with FFFFFF) */ void EffectiveAddressRead(int mode,char Size,int Rreg,int Dreg,const char *flags,int SaveEDX) { char* Regname=""; int MaskMode; char Flags[8]; AccessType = NORMAL; strcpy(Flags,flags); /* Which Masking to Use */ if (Flags[5] != '-') MaskMode = 2; else MaskMode = 1; if (SaveEDX) Flags[3] = 'D'; else Flags[3] = '-'; switch (Size) { case 66: Regname = regnamesshort[Dreg]; break; case 87: Regname = regnamesword[Dreg]; break; case 76: Regname = regnameslong[Dreg]; break; } switch (mode & 15) { case 0: /* Read 32 bits - No prefix */ fprintf(fp, "\t\t mov %s,[%s+%s*4]\n",regnameslong[Dreg],REG_DAT,regnameslong[Rreg]); break; case 1: /* Read 32 bits - No prefix */ fprintf(fp, "\t\t mov %s,[%s+%s*4]\n",regnameslong[Dreg],REG_ADD,regnameslong[Rreg]); break; case 2: EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Read(Size,EDI,Flags,MaskMode); if (Dreg != EAX) { fprintf(fp, "\t\t mov %s,EAX\n",regnameslong[Dreg]); } break; case 3: EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Read(Size,EDI,Flags,MaskMode); if (Dreg != EAX) { fprintf(fp, "\t\t mov %s,EAX\n",regnameslong[Dreg]); } break; case 4: EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Read(Size,EDI,Flags,MaskMode); if (Dreg != EAX) { fprintf(fp, "\t\t mov %s,EAX\n",regnameslong[Dreg]); } break; case 5: EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Read(Size,EDI,Flags,MaskMode); if (Dreg != EAX) { fprintf(fp, "\t\t mov %s,EAX\n",regnameslong[Dreg]); } break; case 6: EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Read(Size,EDI,Flags,MaskMode); if (Dreg != EAX) { fprintf(fp, "\t\t mov %s,EAX\n",regnameslong[Dreg]); } break; case 7: EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Read(Size,EDI,Flags,MaskMode); if (Dreg != EAX) { fprintf(fp, "\t\t mov %s,EAX\n",regnameslong[Dreg]); } break; case 8: EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Read(Size,EDI,Flags,MaskMode); if (Dreg != EAX) { fprintf(fp, "\t\t mov %s,EAX\n",regnameslong[Dreg]); } break; case 9: EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Read(Size,EDI,Flags,MaskMode); if (Dreg != EAX) { fprintf(fp, "\t\t mov %s,EAX\n",regnameslong[Dreg]); } break; case 10: EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Read(Size,EDI,Flags,MaskMode); if (Dreg != EAX) { fprintf(fp, "\t\t mov %s,EAX\n",regnameslong[Dreg]); } break; case 11: /* Immediate - for SR or CCR see ReadCCR() */ if (Size == 'L') { Memory_Fetch('L',Dreg,FALSE); fprintf(fp, "\t\t add esi,byte 4\n"); } else { Memory_Fetch('W',Dreg,FALSE); fprintf(fp, "\t\t add esi,byte 2\n"); }; break; } } /* * EA = Effective Address from Instruction * Size = Byte,Word or Long * Rreg = Register with Register Number in * * Writes from EAX */ void EffectiveAddressWrite(int mode,char Size,int Rreg,int CalcAddress,const char *flags,int SaveEDX) { int MaskMode; char* Regname=""; char Flags[8]; strcpy(Flags,flags); /* Which Masking to Use ? */ if (CalcAddress) { if (Flags[5] != '-') MaskMode = 2; else MaskMode = 1; } else MaskMode = 0; if (SaveEDX) Flags[3] = 'D'; else Flags[3] = '-'; switch (Size) { case 66: Regname = regnamesshort[0]; break; case 87: Regname = regnamesword[0]; break; case 76: Regname = regnameslong[0]; break; } switch (mode & 15) { case 0: fprintf(fp, "\t\t mov [%s+%s*4],%s\n",REG_DAT,regnameslong[Rreg],Regname); break; case 1: if (Size == 66) { /* Not Allowed */ fprintf(fp, "DUFF CODE!\n"); } else { if (Size == 87) { fprintf(fp, "\t\t cwde\n"); } fprintf(fp, "\t\t mov [%s+%s*4],%s\n",REG_ADD,regnameslong[Rreg],regnameslong[0]); } break; case 2: if (CalcAddress) EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Write(Size,EDI,EAX,Flags,MaskMode); break; case 3: if (CalcAddress) EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Write(Size,EDI,EAX,Flags,MaskMode); break; case 4: if (CalcAddress) EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); Memory_Write(Size,EDI,EAX,Flags,MaskMode); break; case 5: if (CalcAddress) { fprintf(fp, "\t\t push EAX\n"); EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); fprintf(fp, "\t\t pop EAX\n"); } Memory_Write(Size,EDI,EAX,Flags,MaskMode); break; case 6: if (CalcAddress) { fprintf(fp, "\t\t push EAX\n"); EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); fprintf(fp, "\t\t pop EAX\n"); } Memory_Write(Size,EDI,EAX,Flags,MaskMode); break; case 7: if (CalcAddress) { fprintf(fp, "\t\t push EAX\n"); EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); fprintf(fp, "\t\t pop EAX\n"); } Memory_Write(Size,EDI,EAX,Flags,MaskMode); break; case 8: if (CalcAddress) { fprintf(fp, "\t\t push EAX\n"); EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); fprintf(fp, "\t\t pop EAX\n"); } Memory_Write(Size,EDI,EAX,Flags,MaskMode); break; case 9: if (CalcAddress) { fprintf(fp, "\t\t push EAX\n"); EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); fprintf(fp, "\t\t pop EAX\n"); } Memory_Write(Size,EDI,EAX,Flags,MaskMode); break; case 10: if (CalcAddress) { fprintf(fp, "\t\t push EAX\n"); EffectiveAddressCalculate(mode,Size,Rreg,SaveEDX); fprintf(fp, "\t\t pop EAX\n"); } Memory_Write(Size,EDI,EAX,Flags,MaskMode); break; case 11: /* SR, CCR - Chain to correct routine */ WriteCCR(Size); } } /* Condition Decode Routines */ /* * mode = condition to check for * * Returns LABEL that is jumped to if condition is Condition * * Some conditions clobber AH */ char *ConditionDecode(int mode, int Condition) { char *Label = GenerateLabel(0,1); switch (mode) { case 0: /* A - Always */ if (Condition) { fprintf(fp, "\t\t jmp near %s\n",Label); } break; case 1: /* F - Never */ if (!Condition) { fprintf(fp, "\t\t jmp near %s\n",Label); } break; case 2: /* Hi */ fprintf(fp, "\t\t mov ah,dl\n"); fprintf(fp, "\t\t sahf\n"); if (Condition) { fprintf(fp, "\t\t ja near %s\n",Label); } else { fprintf(fp, "\t\t jbe near %s\n",Label); } break; case 3: /* Ls */ fprintf(fp, "\t\t mov ah,dl\n"); fprintf(fp, "\t\t sahf\n"); if (Condition) { fprintf(fp, "\t\t jbe near %s\n",Label); } else { fprintf(fp, "\t\t ja near %s\n",Label); } break; case 4: /* CC */ fprintf(fp, "\t\t test dl,1H\t\t;check carry\n"); if (Condition) { fprintf(fp, "\t\t jz near %s\n",Label); } else { fprintf(fp, "\t\t jnz near %s\n",Label); } break; case 5: /* CS */ fprintf(fp, "\t\t test dl,1H\t\t;check carry\n"); if (Condition) { fprintf(fp, "\t\t jnz near %s\n",Label); } else { fprintf(fp, "\t\t jz near %s\n",Label); } break; case 6: /* NE */ fprintf(fp, "\t\t test dl,40H\t\t;Check zero\n"); if (Condition) { fprintf(fp, "\t\t jz near %s\n",Label); } else { fprintf(fp, "\t\t jnz near %s\n",Label); } break; case 7: /* EQ */ fprintf(fp, "\t\t test dl,40H\t\t;Check zero\n"); if (Condition) { fprintf(fp, "\t\t jnz near %s\n",Label); } else { fprintf(fp, "\t\t jz near %s\n",Label); } break; case 8: /* VC */ fprintf(fp, "\t\t test dh,8H\t\t;Check Overflow\n"); if (Condition) { fprintf(fp, "\t\t jz near %s\n", Label); } else { fprintf(fp, "\t\t jnz near %s\n", Label); } break; case 9: /* VS */ fprintf(fp, "\t\t test dh,8H\t\t;Check Overflow\n"); if (Condition) { fprintf(fp, "\t\t jnz near %s\n", Label); } else { fprintf(fp, "\t\t jz near %s\n", Label); } break; case 10: /* PL */ fprintf(fp,"\t\t test dl,80H\t\t;Check Sign\n"); if (Condition) { fprintf(fp, "\t\t jz near %s\n", Label); } else { fprintf(fp, "\t\t jnz near %s\n", Label); } break; case 11: /* MI */ fprintf(fp,"\t\t test dl,80H\t\t;Check Sign\n"); if (Condition) { fprintf(fp, "\t\t jnz near %s\n", Label); } else { fprintf(fp, "\t\t jz near %s\n", Label); } break; case 12: /* GE */ fprintf(fp, "\t\t or edx,200h\n"); fprintf(fp, "\t\t push edx\n"); fprintf(fp, "\t\t popf\n"); if (Condition) { fprintf(fp, "\t\t jge near %s\n",Label); } else { fprintf(fp, "\t\t jl near %s\n",Label); } break; case 13: /* LT */ fprintf(fp, "\t\t or edx,200h\n"); fprintf(fp, "\t\t push edx\n"); fprintf(fp, "\t\t popf\n"); if (Condition) { fprintf(fp, "\t\t jl near %s\n",Label); } else { fprintf(fp, "\t\t jge near %s\n",Label); } break; case 14: /* GT */ fprintf(fp, "\t\t or edx,200h\n"); fprintf(fp, "\t\t push edx\n"); fprintf(fp, "\t\t popf\n"); if (Condition) { fprintf(fp, "\t\t jg near %s\n",Label); } else { fprintf(fp, "\t\t jle near %s\n",Label); } break; case 15: /* LE */ fprintf(fp, "\t\t or edx,200h\n"); fprintf(fp, "\t\t push edx\n"); fprintf(fp, "\t\t popf\n"); if (Condition) { fprintf(fp, "\t\t jle near %s\n",Label); } else { fprintf(fp, "\t\t jg near %s\n",Label); } break; } return Label; } /* * mode = condition to check for * SetWhat = text for assembler command (usually AL or address descriptor) * * Some conditions clobber AH */ void ConditionCheck(int mode, char *SetWhat) { switch (mode) { case 0: /* A - Always */ fprintf(fp, "\t\t mov %s,byte 0ffh\n",SetWhat); break; case 1: /* F - Never */ if (SetWhat[1] == 'L') { ClearRegister(EAX); } else { fprintf(fp, "\t\t mov %s,byte 0h\n",SetWhat); } break; case 2: /* Hi */ fprintf(fp, "\t\t mov ah,dl\n"); fprintf(fp, "\t\t sahf\n"); fprintf(fp, "\t\t seta %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 3: /* Ls */ fprintf(fp, "\t\t mov ah,dl\n"); fprintf(fp, "\t\t sahf\n"); fprintf(fp, "\t\t setbe %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 4: /* CC */ fprintf(fp, "\t\t test dl,1\t\t;Check Carry\n"); fprintf(fp, "\t\t setz %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 5: /* CS */ fprintf(fp, "\t\t test dl,1\t\t;Check Carry\n"); fprintf(fp, "\t\t setnz %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 6: /* NE */ fprintf(fp, "\t\t test dl,40H\t\t;Check Zero\n"); fprintf(fp, "\t\t setz %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 7: /* EQ */ fprintf(fp, "\t\t test dl,40H\t\t;Check Zero\n"); fprintf(fp, "\t\t setnz %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 8: /* VC */ fprintf(fp, "\t\t test dh,8H\t\t;Check Overflow\n"); fprintf(fp, "\t\t setz %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 9: /* VS */ fprintf(fp, "\t\t test dh,8H\t\t;Check Overflow\n"); fprintf(fp, "\t\t setnz %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 10: /* PL */ fprintf(fp, "\t\t test dl,80H\t\t;Check Sign\n"); fprintf(fp, "\t\t setz %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 11: /* MI */ fprintf(fp, "\t\t test dl,80H\t\t;Check Sign\n"); fprintf(fp, "\t\t setnz %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 12: /* GE */ fprintf(fp, "\t\t or edx,200h\n"); fprintf(fp, "\t\t push edx\n"); fprintf(fp, "\t\t popf\n"); fprintf(fp, "\t\t setge %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 13: /* LT */ fprintf(fp, "\t\t or edx,200h\n"); fprintf(fp, "\t\t push edx\n"); fprintf(fp, "\t\t popf\n"); fprintf(fp, "\t\t setl %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 14: /* GT */ fprintf(fp, "\t\t or edx,200h\n"); fprintf(fp, "\t\t push edx\n"); fprintf(fp, "\t\t popf\n"); fprintf(fp, "\t\t setg %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; case 15: /* LE */ fprintf(fp, "\t\t or edx,200h\n"); fprintf(fp, "\t\t push edx\n"); fprintf(fp, "\t\t popf\n"); fprintf(fp, "\t\t setle %s\n",SetWhat); fprintf(fp, "\t\t neg byte %s\n",SetWhat); break; } } /**********************************************************************/ /* Instructions - Each routine generates a range of instruction codes */ /**********************************************************************/ /* * Immediate Commands * * ORI 00xx * ANDI 02xx * SUBI 04xx * ADDI 06xx * EORI 0axx * CMPI 0cxx * */ void dump_imm( int type, int leng, int mode, int sreg ) { int Opcode,BaseCode ; char Size=' ' ; char * RegnameEBX="" ; char * Regname="" ; char * OpcodeName[16] = {"or ", "and", "sub", "add",0,"xor","cmp",0} ; int allow[] = {1,0,1,1, 1,1,1,1, 1,0,0,0, 0,0,0,0, 0,0,0,1, 1} ; Opcode = (type << 9) | ( leng << 6 ) | ( mode << 3 ) | sreg; BaseCode = Opcode & 0xfff8; if (mode == 7) BaseCode |= sreg ; #ifdef A7ROUTINE if ((leng == 0) && (sreg == 7) && (mode > 2) && (mode < 5)) { BaseCode |= sreg ; } #endif if (type != 4) /* Not Valid (for this routine) */ { int Dest = EAtoAMN(Opcode, FALSE); int SetX; /* ADDI & SUBI also set X flag */ SetX = ((type == 2) || (type == 3)); switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameEBX = regnamesshort[EBX]; break; case 1: Size = 'W'; Regname = regnamesword[0]; RegnameEBX = regnamesword[EBX]; break; case 2: Size = 'L'; Regname = regnameslong[0]; RegnameEBX = regnameslong[EBX]; break; } if (allow[Dest]) { if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); /* Save Previous PC if Memory Access */ if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (mode < 2) { if (Size != 'L') TimingCycles += (CPU==2) ? 4 : 8; else { TimingCycles += (CPU==2) ? 8 : 14; if ((type != 1) && (type!=6)) TimingCycles += 2 ; } } else { if (type != 6) { if (Size != 'L') TimingCycles += (CPU==2) ? 4 : 12 ; else TimingCycles += (CPU==2) ? 4 : 20 ; } else { if (Size != 'L') TimingCycles += (CPU==2) ? 4 : 8 ; else TimingCycles += (CPU==2) ? 4 : 12 ; } } fprintf(fp, "\t\t and ecx,byte 7\n"); /* Immediate Mode Data */ EffectiveAddressRead(11,Size,EBX,EBX,"--C-S-B",FALSE); /* Source Data */ EffectiveAddressRead(Dest,Size,ECX,EAX,"-BC-SDB",FALSE); /* The actual work */ fprintf(fp, "\t\t %s %s,%s\n", OpcodeName[type], Regname, RegnameEBX ); SetFlags(Size,EAX,FALSE,SetX,TRUE); if (type != 6) /* CMP no update */ EffectiveAddressWrite(Dest,Size,ECX,EAX,"---DS-B",FALSE); Completed(); } } else { /* Logicals are allowed to alter SR/CCR */ if ((!SetX) && (Dest == 11) && (Size != 'L') && (type != 6)) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 20 ; if (Size=='W') { /* If SR then must be in Supervisor Mode */ char *Label = GenerateLabel(0,1); fprintf(fp, "\t\t test byte [%s],20h \t\t\t; Supervisor Mode ?\n",REG_SRH); fprintf(fp, "\t\t jne near %s\n\n",Label); /* User Mode - Exception */ Exception(8,BaseCode); fprintf(fp, "%s:\n",Label); } /* Immediate Mode Data */ EffectiveAddressRead(11,Size,EBX,EBX,"---DS-B",TRUE); ReadCCR(Size,ECX); fprintf(fp, "\t\t %s %s,%s\n", OpcodeName[type], Regname, RegnameEBX ); WriteCCR(Size); Completed(); } else { /* Illegal Opcode */ OpcodeArray[BaseCode] = -1; BaseCode = -1; } } } else { BaseCode = -2; } OpcodeArray[Opcode] = BaseCode; } void immediate(void) { int type, size, mode, sreg ; for (type = 0 ; type < 0x7; type++) for (size = 0 ; size < 3 ; size++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dump_imm( type, size, mode, sreg ) ; } /* * Bitwise Codes * */ void dump_bit_dynamic( int sreg, int type, int mode, int dreg ) { int Opcode, BaseCode ; char Size ; char *EAXReg,*ECXReg, *Label ; char allow[] = "0-2345678-------" ; int Dest ; /* BTST allows x(PC) and x(PC,xr.s) - others do not */ if (type == 0) { allow[9] = '9'; allow[10] = 'a'; allow[11] = 'b'; // dave fix to nhl } Opcode = 0x0100 | (sreg << 9) | (type<<6) | (mode<<3) | dreg ; BaseCode = Opcode & 0x01f8 ; if (mode == 7) BaseCode |= dreg ; // A7+, A7- #ifdef A7ROUTINE if ((mode > 2) && (mode < 5)) { if (dreg == 7) BaseCode |= dreg; } #endif Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0xf] != '-') { if (mode == 0) /* long*/ { /* Modify register memory directly */ Size = 'L' ; EAXReg = REG_DAT_EBX; ECXReg = regnameslong[ECX]; } else { Size = 'B' ; EAXReg = regnamesshort[EAX]; ECXReg = regnamesshort[ECX]; } if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); /* Save Previous PC if Memory Access */ if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (mode<2) { switch (type) { case 0: TimingCycles += 6 ; break; case 1: case 3: TimingCycles += 8 ; break; case 2: TimingCycles += 10; break; } } else { if (type==0) TimingCycles += 4; else TimingCycles += 8; } /* Only need this sorted out if a register is involved */ if (Dest < 7) { fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); } /* Get bit number and create mask in ECX */ fprintf(fp, "\t\t shr ecx, byte 9\n"); fprintf(fp, "\t\t and ecx, byte 7\n"); fprintf(fp, "\t\t mov ecx, [%s+ECX*4]\n",REG_DAT); if (Size == 'L') fprintf(fp, "\t\t and ecx, byte 31\n"); else fprintf(fp, "\t\t and ecx, byte 7\n"); #ifdef QUICKZERO fprintf(fp,"\t\t mov eax,1\n"); #else fprintf(fp,"\t\t xor eax,eax\n"); fprintf(fp,"\t\t inc eax\n"); #endif fprintf(fp,"\t\t shl eax,cl\n"); fprintf(fp,"\t\t mov ecx,eax\n"); if (mode != 0) EffectiveAddressRead(Dest,Size,EBX,EAX,"-BCDSDB",TRUE); /* All commands copy existing bit to Zero Flag */ Label = GenerateLabel(0,1); fprintf(fp,"\t\t or edx,byte 40h\t; Set Zero Flag\n"); fprintf(fp,"\t\t test %s,%s\n",EAXReg,ECXReg); fprintf(fp,"\t\t jz short %s\n",Label); fprintf(fp,"\t\t xor edx,byte 40h\t; Clear Zero Flag\n"); fprintf(fp,"%s:\n",Label); /* Some then modify the data */ switch (type) { case 0: /* btst*/ break; case 1: /* bchg*/ fprintf(fp,"\t\t xor %s,%s\n",EAXReg,ECXReg); break; case 2: /* bclr*/ fprintf(fp,"\t\t not ecx\n"); fprintf(fp,"\t\t and %s,%s\n",EAXReg,ECXReg); break; case 3: /* bset*/ fprintf(fp,"\t\t or %s,%s\n",EAXReg,ECXReg); break; } if ((mode !=0) && (type != 0)) EffectiveAddressWrite(Dest,Size,EBX,FALSE,"---DS-B",TRUE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void bitdynamic(void) /* dynamic non-immediate bit operations*/ { int type, sreg, mode, dreg ; for (sreg = 0 ; sreg < 8 ; sreg++) for (type = 0 ; type < 4 ; type++) for (mode = 0 ; mode < 8 ;mode++) for (dreg = 0 ; dreg < 8 ;dreg++) dump_bit_dynamic( sreg, type, mode, dreg ) ; } void dump_bit_static(int type, int mode, int dreg ) { int Opcode, BaseCode ; char Size ; char *EAXReg,*ECXReg, *Label ; char allow[] = "0-2345678-------" ; int Dest ; /* BTST allows x(PC) and x(PC,xr.s) - others do not */ if (type == 0) { allow[9] = '9'; allow[10] = 'a'; } Opcode = 0x0800 | (type<<6) | (mode<<3) | dreg ; BaseCode = Opcode & 0x08f8 ; if (mode == 7) BaseCode |= dreg ; // A7+, A7- #ifdef A7ROUTINE if ((mode > 2) && (mode < 5)) { if (dreg == 7) BaseCode |= dreg; } #endif Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0xf] != '-') { if (mode == 0) /* long*/ { /* Modify register memory directly */ Size = 'L' ; EAXReg = REG_DAT_EBX; ECXReg = regnameslong[ECX]; } else { Size = 'B' ; EAXReg = regnamesshort[EAX]; ECXReg = regnamesshort[ECX]; } if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); /* Save Previous PC if Memory Access */ if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (mode<2) { switch (type) { case 0: TimingCycles += 10 ; break ; case 1: case 3: TimingCycles += 12 ; break ; case 2: TimingCycles += 14 ; break ; } } else { if (type != 0) TimingCycles += 12 ; else TimingCycles += 8 ; } /* Only need this sorted out if a register is involved */ if (Dest < 7) { fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx, byte 7\n"); } /* Get bit number and create mask in ECX */ Memory_Fetch('W',ECX,FALSE); fprintf(fp, "\t\t add esi,byte 2\n"); if (Size == 'L') fprintf(fp, "\t\t and ecx, byte 31\n"); else fprintf(fp, "\t\t and ecx, byte 7\n"); #ifdef QUICKZERO fprintf(fp,"\t\t mov eax,1\n"); #else fprintf(fp,"\t\t xor eax,eax\n"); fprintf(fp,"\t\t inc eax\n"); #endif fprintf(fp,"\t\t shl eax,cl\n"); fprintf(fp,"\t\t mov ecx,eax\n"); if (mode != 0) EffectiveAddressRead(Dest,Size,EBX,EAX,"-BCDSDB",TRUE); /* All commands copy existing bit to Zero Flag */ Label = GenerateLabel(0,1); fprintf(fp,"\t\t or edx,byte 40h\t; Set Zero Flag\n"); fprintf(fp,"\t\t test %s,%s\n",EAXReg,ECXReg); fprintf(fp,"\t\t jz short %s\n",Label); fprintf(fp,"\t\t xor edx,byte 40h\t; Clear Zero Flag\n"); fprintf(fp,"%s:\n",Label); /* Some then modify the data */ switch (type) { case 0: /* btst*/ break; case 1: /* bchg*/ fprintf(fp,"\t\t xor %s,%s\n",EAXReg,ECXReg); break; case 2: /* bclr*/ fprintf(fp,"\t\t not ecx\n"); fprintf(fp,"\t\t and %s,%s\n",EAXReg,ECXReg); break; case 3: /* bset*/ fprintf(fp,"\t\t or %s,%s\n",EAXReg,ECXReg); break; } if ((mode !=0) && (type != 0)) EffectiveAddressWrite(Dest,Size,EBX,FALSE,"---DS-B",TRUE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void bitstatic(void) /* static non-immediate bit operations*/ { int type, mode, dreg ; for (type = 0 ; type < 4 ; type++) for (mode = 0 ; mode < 8 ;mode++) for (dreg = 0 ; dreg < 8 ;dreg++) dump_bit_static( type, mode, dreg ) ; } /* * Move Peripheral * */ void movep(void) { int sreg,dir,leng,dreg ; int Opcode, BaseCode ; for (sreg = 0 ; sreg < 8 ; sreg++) { for (dir = 0 ; dir < 2 ; dir++) { for (leng = 0 ; leng < 2 ; leng++) { for (dreg = 0 ; dreg < 8 ; dreg++) { Opcode = 0x0108 | (sreg<<9) | (dir<<7) | (leng<<6) | dreg; BaseCode = Opcode & 0x01c8 ; if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (leng == 0) /* word */ TimingCycles += 16 ; else TimingCycles += 24 ; /* Save Flags Register (so we only do it once) */ fprintf(fp, "\t\t push edx\n"); fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); /* Get Address to Read/Write in EDI */ EffectiveAddressCalculate(5,'L',EBX,FALSE); fprintf(fp, "\t\t shr ecx,byte 9\n"); fprintf(fp, "\t\t and ecx,byte 7\n"); if (dir == 0) /* from memory to register*/ { Memory_Read('B',EDI,"-BC-SDB",2); /* mask first call */ fprintf(fp,"\t\t mov bh,al\n"); fprintf(fp,"\t\t add edi,byte 2\n"); Memory_Read('B',EDI,"-BC-SDB",0); /* not needed then */ fprintf(fp,"\t\t mov bl,al\n"); if (leng == 0) /* word d(Ax) into Dx.W*/ { fprintf(fp,"\t\t mov [%s+ecx*4],bx\n",REG_DAT); } else /* long d(Ax) into Dx.L*/ { fprintf(fp,"\t\t add edi,byte 2\n"); fprintf(fp,"\t\t shl ebx,16\n"); Memory_Read('B',EDI,"-BC-SDB",0); fprintf(fp,"\t\t mov bh,al\n"); fprintf(fp,"\t\t add edi,byte 2\n"); Memory_Read('B',EDI,"-BC-S-B",0); fprintf(fp,"\t\t mov bl,al\n"); fprintf(fp,"\t\t mov [%s+ecx*4],ebx\n",REG_DAT); } } else /* Register to Memory*/ { fprintf(fp,"\t\t mov eax,[%s+ecx*4]\n",REG_DAT); /* Move bytes into Line */ if (leng == 1) fprintf(fp,"\t\t rol eax,byte 8\n"); else fprintf(fp,"\t\t rol eax,byte 24\n"); Memory_Write('B',EDI,EAX,"A---SDB",2); /* Mask First */ fprintf(fp,"\t\t add edi,byte 2\n"); fprintf(fp,"\t\t rol eax,byte 8\n"); if (leng == 1) /* long*/ { Memory_Write('B',EDI,EAX,"A---SDB",0); fprintf(fp,"\t\t add edi,byte 2\n"); fprintf(fp,"\t\t rol eax,byte 8\n"); Memory_Write('B',EDI,EAX,"A---SDB",0); fprintf(fp,"\t\t add edi,byte 2\n"); fprintf(fp,"\t\t rol eax,byte 8\n"); } Memory_Write('B',EDI,EAX,"A---S-B",0); } fprintf(fp, "\t\t pop edx\n"); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } } } void movecodes(int allowfrom[],int allowto[],int Start,char Size) /* MJC */ { int Opcode; int Src,Dest; int SaveEDX; int BaseCode; for (Opcode=Start;Opcode<Start+0x1000;Opcode++) { /* Mask our Registers */ BaseCode = Opcode & (Start + 0x1f8); /* Unless Mode = 7 */ if ((BaseCode & 0x38) == 0x38) BaseCode |= (Opcode & 7); if ((BaseCode & 0x1c0) == 0x1c0) BaseCode |= (Opcode & 0xE00); /* If mode = 3 or 4 and Size = byte and register = A7 */ /* then make it a separate code */ #ifdef A7ROUTINE if (Size == 'B') { if (((Opcode & 0x3F) == 0x1F) || ((Opcode & 0x3F) == 0x27)) { BaseCode |= 0x07; } if (((Opcode & 0xFC0) == 0xEC0) || ((Opcode & 0xFC0) == 0xF00)) { BaseCode |= 0x0E00; } } #endif /* If Source = Data or Address register - combine into same routine */ if (((Opcode & 0x38) == 0x08) && (allowfrom[1])) { BaseCode &= 0xfff7; } if (OpcodeArray[BaseCode] == -2) { Src = EAtoAMN(Opcode, FALSE); Dest = EAtoAMN(Opcode >> 6, TRUE); if ((allowfrom[(Src & 15)]) && (allowto[(Dest & 15)])) { /* If we are not going to calculate the flags */ /* we need to preserve the existing ones */ SaveEDX = (Dest == 1); Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if (((Src >= 2) && (Src <= 10)) || ((Dest >= 2) && (Dest <=10))) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 4 ; if (Src < 7) { if (Dest < 7) { fprintf(fp, "\t\t mov ebx,ecx\n"); if ((Src == 0) && allowfrom[1]) fprintf(fp, "\t\t and ebx,byte 15\n"); else fprintf(fp, "\t\t and ebx,byte 7\n"); EffectiveAddressRead(Src,Size,EBX,EAX,"--CDS-B",SaveEDX); } else { if ((Src == 0) && allowfrom[1]) fprintf(fp, "\t\t and ecx,byte 15\n"); else fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(Src,Size,ECX,EAX,"---DS-B",SaveEDX); } } else { if (Dest < 7) EffectiveAddressRead(Src,Size,EBX,EAX,"--CDS-B",SaveEDX); else EffectiveAddressRead(Src,Size,EBX,EAX,"---DS-B",SaveEDX); } /* No flags if Destination Ax */ if (!SaveEDX) { SetFlags(Size,EAX,TRUE,FALSE,TRUE); } if (Dest < 7) { fprintf(fp, "\t\t shr ecx,9\n"); fprintf(fp, "\t\t and ecx,byte 7\n"); } EffectiveAddressWrite(Dest,Size,ECX,TRUE,"---DS-B",SaveEDX); Completed(); } else { BaseCode = -1; /* Invalid Code */ } } else { BaseCode = OpcodeArray[BaseCode]; } if (OpcodeArray[Opcode] < 0) OpcodeArray[Opcode] = BaseCode; } } void moveinstructions(void) { int allowfrom[] = {1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0}; int allowto[] = {1,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0}; /* For Byte */ movecodes(allowfrom,allowto,0x1000,'B'); /* For Word & Long */ allowto[1] = 1; movecodes(allowfrom,allowto,0x2000,'L'); movecodes(allowfrom,allowto,0x3000,'W'); } /* * * Opcodes 5### * * ADDQ,SUBQ,Scc and DBcc * */ void opcode5(void) { /* ADDQ,SUBQ,Scc and DBcc */ int allowtoScc[] = {1,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0}; int allowtoADDQ[] = {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0}; int Opcode,BaseCode; char Label[32]; char Label2[32]; char Size=' '; char* Regname=""; char* RegnameECX=""; for (Opcode = 0x5000;Opcode < 0x6000;Opcode++) { if ((Opcode & 0xc0) == 0xc0) { /* Scc or DBcc */ BaseCode = Opcode & 0x5FF8; if ((BaseCode & 0x38) == 0x38) BaseCode |= (Opcode & 7); /* If mode = 3 or 4 and register = A7 */ /* then make it a separate code */ #ifdef A7ROUTINE if (((Opcode & 0x3F) == 0x1F) || ((Opcode & 0x3F) == 0x27)) { BaseCode |= 0x07; } #endif if (OpcodeArray[BaseCode] == -2) { OpcodeArray[BaseCode] = BaseCode; if ((BaseCode & 0x38) == 0x8) { /* DBcc */ Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); TimingCycles += 10 ; strcpy(Label,GenerateLabel(BaseCode,1)) ; strcpy(Label2,ConditionDecode((Opcode >> 8) & 0x0F,TRUE)); /* False - Decrement Counter - Loop if not -1 */ fprintf(fp, "\t\t and ecx,byte 7\n"); fprintf(fp, "\t\t mov ax,[%s+ecx*4]\n",REG_DAT); fprintf(fp, "\t\t dec ax\n"); fprintf(fp, "\t\t mov [%s+ecx*4],ax\n",REG_DAT); fprintf(fp, "\t\t inc ax\t\t; Is it -1\n"); fprintf(fp, "\t\t jz short %s\n",Label); fprintf(fp, "\t\t add esi,byte 2\n\n"); Memory_Fetch('W',EAX,TRUE); fprintf(fp, "\t\t add esi,eax\n"); Completed(); /* True - Exit Loop */ fprintf(fp, "%s:\n",Label); fprintf(fp, "%s:\n",Label2); fprintf(fp, "\t\t add esi,byte 4\n"); TimingCycles += 2 ; Completed(); } else { /* Scc */ int Dest = EAtoAMN(Opcode, FALSE); if (allowtoScc[(Dest & 15)]) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (Dest > 1) TimingCycles += 8 ; else TimingCycles += 4 ; if (Dest < 7) { fprintf(fp, "\t\t and ecx,byte 7\n"); } if (Dest > 1) { EffectiveAddressCalculate(Dest,'B',ECX,TRUE); /* ASG - no longer need to mask addresses here */ /* fprintf(fp,"\t\t and edi,0FFFFFFh\n");*/ } ConditionCheck((Opcode >> 8) & 0x0F,"AL"); EffectiveAddressWrite(Dest,'B',ECX,FALSE,"---DS-B",TRUE); /* take advantage of AL being 0 for false, 0xff for true */ /* need to add 2 cycles if register and condition is true */ if (Dest == 0) { fprintf(fp, "\t\t and eax,byte 2\n"); fprintf(fp, "\t\t add eax,byte %d\n",TimingCycles); fprintf(fp, "\t\t sub dword [%s],eax\n",ICOUNT); TimingCycles = -1; } Completed(); } else { OpcodeArray[BaseCode] = -1; BaseCode = -1; } } } else { BaseCode = OpcodeArray[BaseCode]; } OpcodeArray[Opcode] = BaseCode; } else { /* ADDQ or SUBQ */ BaseCode = Opcode & 0x51F8; if ((BaseCode & 0x38) == 0x38) BaseCode |= (Opcode & 7); /* Special for Address Register Direct - Force LONG */ if ((Opcode & 0x38) == 0x8) BaseCode = ((BaseCode & 0xFF3F) | 0x80); /* If mode = 3 or 4 and Size = byte and register = A7 */ /* then make it a separate code */ #ifdef A7ROUTINE if ((Opcode & 0xC0) == 0) { if (((Opcode & 0x3F) == 0x1F) || ((Opcode & 0x3F) == 0x27)) { BaseCode |= 0x07; } } #endif if (OpcodeArray[BaseCode] == -2) { char *Operation; int Dest = EAtoAMN(Opcode, FALSE); int SaveEDX = (Dest == 1); if (allowtoADDQ[(Dest & 15)]) { switch (BaseCode & 0xC0) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameECX = regnamesshort[ECX]; break; case 0x40: Size = 'W'; Regname = regnamesword[0]; RegnameECX = regnamesword[ECX]; break; case 0x80: Size = 'L'; Regname = regnameslong[0]; RegnameECX = regnameslong[ECX]; break; } OpcodeArray[BaseCode] = BaseCode; Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (Dest == 0) /* write to Dx */ { if (Size != 'L') TimingCycles += 4 ; else TimingCycles += 8 ; } if (Dest == 1) { if ((Size == 'L') || (Opcode & 0x100)) /* if long or SUBQ */ TimingCycles += 8 ; else TimingCycles += 4 ; } if (Dest > 1) /* write to mem */ { if (Size != 'L') TimingCycles += 8 ; else TimingCycles += 12 ; } if (Dest < 7) { fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); } if (Dest > 1) { EffectiveAddressRead(Dest,Size,EBX,EAX,"-BCDSDB",SaveEDX); } /* Sub Immediate from Opcode */ fprintf(fp, "\t\t shr ecx,9\n"); Immediate8(); if (Opcode & 0x100) { /* SUBQ */ Operation = "sub"; } else { /* ADDQ */ Operation = "add"; } /* For Data or Address register, operate directly */ /* on the memory location. Don't load into EAX */ if (Dest < 2) { if (Dest == 0) { fprintf(fp, "\t\t %s [%s+ebx*4],%s\n",Operation,REG_DAT,RegnameECX); } else { fprintf(fp, "\t\t %s [%s+ebx*4],%s\n",Operation,REG_ADD,RegnameECX); } } else { fprintf(fp, "\t\t %s %s,%s\n",Operation,Regname,RegnameECX); } /* No Flags for Address Direct */ if (!SaveEDX) { /* Directly after ADD or SUB, so test not needed */ SetFlags(Size,EAX,FALSE,TRUE,TRUE); } if (Dest > 1) { EffectiveAddressWrite(Dest,Size,EBX,FALSE,"---DS-B",FALSE); } Completed(); } else { OpcodeArray[BaseCode] = -1; BaseCode = -1; } } else { BaseCode = OpcodeArray[BaseCode]; } OpcodeArray[Opcode] = BaseCode; } } } /* * Branch Instructions * * BSR, Bcc * */ void branchinstructions(void) { int Opcode,BaseCode; int Counter; char *Label; char jmpLabel[40] ; for (Opcode = 0x60;Opcode < 0x70;Opcode++) { /* Displacement = 0 -> 16 Bit displacement */ BaseCode = Opcode * 0x100; OpcodeArray[BaseCode] = BaseCode; Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 10 ; if (Opcode == 0x60) { Memory_Fetch('W',EAX,TRUE); fprintf(fp, "\t\t add esi,eax\n"); MemoryBanking(BaseCode); Completed(); } else { if (Opcode != 0x61) { Label = ConditionDecode(Opcode & 0x0F,TRUE); /* Code for Failed branch */ fprintf(fp, "\t\t add esi,byte 2\n"); /* 2 less cycles for Failure */ TimingCycles -= 2; Completed(); TimingCycles += 2; /* Successful Branch */ Align(); fprintf(fp, "%s:\n",Label); Memory_Fetch('W',EAX,TRUE); fprintf(fp, "\t\t add esi,eax\n"); MemoryBanking(BaseCode+2); Completed(); } else { /* BSR - Special Case */ TimingCycles += 8 ; Memory_Fetch('W',EBX,TRUE); fprintf(fp, "\t\t add ebx,esi\n"); fprintf(fp, "\t\t add esi,byte 2\n"); PushPC(ECX,EAX,"-B-DS-B",1); fprintf(fp, "\t\t mov esi,ebx\n"); MemoryBanking(BaseCode+3); Completed(); } } /* 8 Bit Displacement */ Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode+1,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 10 ; if (Opcode > 0x60) { if (Opcode != 0x61) { Label = ConditionDecode(Opcode & 0x0F,TRUE); /* Code for Failed branch */ TimingCycles -= 2; Completed(); TimingCycles += 2; /* Successful Branch */ Align(); fprintf(fp, "%s:\n",Label); } else { /* BSR - Special Case */ TimingCycles += 8 ; PushPC(EDI,EBX,"--CDS-B",1); } } /* Common Ending */ fprintf(fp, "\t\t movsx eax,cl ; Sign Extend displacement\n"); fprintf(fp, "\t\t add esi,eax\n"); MemoryBanking(BaseCode+5); Completed(); /* Fill up Opcode Array */ for (Counter=1;Counter<0x100;Counter++) OpcodeArray[BaseCode+Counter] = BaseCode+1; if(CPU==2) { /* 8 bit 0xff & 68020 instruction - 32 bit displacement */ Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode+0xff,0)); sprintf( jmpLabel, GenerateLabel(BaseCode+0xff,1) ) ; fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 10 ; if (Opcode == 0x60) { /* bra - always branch */ Memory_Fetch('L',EAX,FALSE); fprintf(fp, "\t\t add esi,eax\n"); MemoryBanking(BaseCode+6); Completed(); } else { if (Opcode != 0x61) { Label = ConditionDecode(Opcode & 0x0F,TRUE); /* Code for Failed branch */ fprintf(fp, "\t\t add esi,byte 4\n"); TimingCycles -= 2; Completed(); TimingCycles += 2; /* Successful Branch */ Align(); fprintf(fp, "%s:\n",Label); Memory_Fetch('L',EAX,FALSE); fprintf(fp, "\t\t add esi,eax\n"); MemoryBanking(BaseCode+8); Completed(); } else { /* BSR - Special Case */ TimingCycles += 8 ; Memory_Fetch('L',EBX,TRUE); fprintf(fp, "\t\t add ebx,esi\n"); fprintf(fp, "\t\t add esi,byte 4\n"); PushPC(ECX,EAX,"-B-DS-B",1); fprintf(fp, "\t\t mov esi,ebx\n"); MemoryBanking(BaseCode+9); Completed(); } } OpcodeArray[BaseCode+0xff] = BaseCode+0xff; } } } /* * Move Quick Commands * * Fairly simple, as only allowed to Data Registers * */ void moveq(void) { int Count; /* The Code */ Align(); fprintf(fp, "%s:\n",GenerateLabel(0x7000,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 4 ; fprintf(fp, "\t\t movsx eax,cl\n"); fprintf(fp, "\t\t shr ecx,9\n"); fprintf(fp, "\t\t and ecx,byte 7\n"); SetFlags('L',EAX,TRUE,FALSE,FALSE); EffectiveAddressWrite(0,'L',ECX,TRUE,"---DS-B",FALSE); Completed(); /* Set OpcodeArray (Not strictly correct, since some are illegal!) */ for (Count=0x7000;Count<0x8000;Count++) { OpcodeArray[Count] = 0x7000; } } /* * Extended version of Add & Sub commands * */ void addx_subx(void) { int Opcode, BaseCode ; int regx,type,leng,rm,regy,mode ; int ModeModX; int ModeModY; char Size=' ' ; char * Regname="" ; char * RegnameEBX="" ; char * Operand=""; char * Label; for (type = 0 ; type < 2 ; type ++) /* 0=subx, 1=addx */ for (regx = 0 ; regx < 8 ; regx++) for (leng = 0 ; leng < 3 ; leng++) for (rm = 0 ; rm < 2 ; rm++) for (regy = 0 ; regy < 8 ; regy++) { Opcode = 0x9100 | (type<<14) | (regx<<9) | (leng<<6) | (rm<<3) | regy ; BaseCode = Opcode & 0xd1c8 ; ModeModX = 0; ModeModY = 0; #ifdef A7ROUTINE if ((rm == 1) && (leng == 0)) { if (regx == 7) { BaseCode |= (regx << 9); ModeModY = 16; } if (regy == 7) { BaseCode |= regy; ModeModX = 16; } } #endif if (rm == 0) mode = 0 ; else mode = 4 ; switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameEBX = regnamesshort[EBX]; break; case 1: Size = 'W'; Regname = regnamesword[0]; RegnameEBX = regnamesword[EBX]; break; case 2: Size = 'L'; Regname = regnameslong[0]; RegnameEBX = regnameslong[EBX]; break; } if (OpcodeArray[BaseCode] == -2) { if (type == 0) Operand = "sbb"; else Operand = "adc"; Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if (mode == 4) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); /* don't add in EA timing for ADDX,SUBX */ AddEACycles = 0 ; if (rm == 0) /* reg to reg */ { if (Size != 'L') TimingCycles += 4 ; else TimingCycles += 8 ; } else { if (Size != 'L') TimingCycles += 18 ; else TimingCycles += 30 ; } fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx, byte 7\n"); fprintf(fp, "\t\t shr ecx, byte 9\n"); fprintf(fp, "\t\t and ecx, byte 7\n"); /* Get Source */ EffectiveAddressRead(mode+ModeModX,Size,EBX,EBX,"--CDS-B",FALSE); /* Get Destination (if needed) */ if (mode == 4) EffectiveAddressRead(mode+ModeModY,Size,ECX,EAX,"-BCDSDB",FALSE); /* Copy the X flag into the Carry Flag */ CopyX(); /* Do the sums */ if (mode == 0) fprintf(fp, "\t\t %s [%s+ecx*4],%s\n",Operand,REG_DAT,RegnameEBX); else fprintf(fp, "\t\t %s %s,%s\n",Operand,Regname,RegnameEBX); /* Preserve old Z flag */ fprintf(fp, "\t\t mov ebx,edx\n"); /* Set the Flags */ SetFlags(Size,EAX,FALSE,TRUE,FALSE); /* Handle the Z flag */ Label = GenerateLabel(0,1); fprintf(fp, "\t\t jnz short %s\n\n",Label); fprintf(fp, "\t\t and dl,0BFh ; Remove Z\n"); fprintf(fp, "\t\t and bl,40h ; Mask out Old Z\n"); fprintf(fp, "\t\t or dl,bl ; Copy across\n\n"); fprintf(fp, "%s:\n",Label); /* Update the Data (if needed) */ if (mode == 4) EffectiveAddressWrite(mode,Size,ECX,FALSE,"---DS-B",TRUE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } /* * Logicals / Simple Maths (+ and -) * * OR,AND,CMP,EOR,ADD and SUB * */ void dumpx( int start, int reg, int type, char * Op, int dir, int leng, int mode, int sreg ) { int Opcode,BaseCode ; char Size=' ' ; char * RegnameECX="" ; char * Regname="" ; int Dest ; int SaveEDX ; int SaveDir; char * allow="" ; char * allowtypes[] = { "0-23456789ab----", "--2345678-------", "0123456789ab----", "0-2345678-------"}; SaveDir = dir; switch (type) { case 0: /* or and*/ if (dir == 0) allow = allowtypes[0]; else allow = allowtypes[1]; break ; case 1: /* cmp*/ allow = allowtypes[2] ; break ; case 2: /* eor*/ allow = allowtypes[3] ; break ; case 3: /* adda suba cmpa*/ allow = allowtypes[2] ; break ; case 4: /* sub add*/ if (dir == 0) allow = allowtypes[0] ; else allow = allowtypes[1] ; break ; } if ((type == 4) && (dir == 0) && (leng > 0)) { allow = allowtypes[2] ; /* word and long ok*/ } Opcode = start | (reg << 9 ) | (dir<<8) | (leng<<6) | (mode<<3) | sreg; BaseCode = Opcode & 0xf1f8; if (mode == 7) BaseCode |= sreg ; #ifdef A7ROUTINE if ((mode == 3 || mode == 4) && ( leng == 0 ) && (sreg == 7 )) BaseCode |= sreg ; #endif /* If Source = Data or Address register - combine into same routine */ if (((Opcode & 0x38) == 0x08) && (allow[1] != '-')) { BaseCode &= 0xfff7; } Dest = EAtoAMN(Opcode, FALSE); SaveEDX = (Dest == 1) || (type == 3); if (allow[Dest&0xf] != '-') { if (OpcodeArray[BaseCode] == -2) { switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameECX = regnamesshort[ECX]; break; case 1: Size = 'W'; Regname = regnamesword[0]; RegnameECX = regnamesword[ECX]; break; case 2: Size = 'L'; Regname = regnameslong[0]; RegnameECX = regnameslong[ECX]; break; case 3: /* cmpa adda suba */ if (dir == 0) { Size = 'W'; Regname = regnamesword[0]; RegnameECX = regnamesword[ECX]; } else { Size = 'L'; Regname = regnameslong[0]; RegnameECX = regnameslong[ECX]; } dir = 0 ; break ; } Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (dir==0) { if (Size != 'L') TimingCycles += 4; else TimingCycles += 6; } else { if (Size != 'L') TimingCycles += 8; else TimingCycles += 12; } if ((mode == 0) && (dir==0) && (Size == 'L')) TimingCycles += 2 ; if ((mode == 1) && (dir==0) && (Size != 'L')) TimingCycles += 4 ; if (Dest < 7) /* Others do not need reg.no. */ { fprintf(fp, "\t\t mov ebx,ecx\n"); if ((Dest == 0) & (allow[1] != '-')) fprintf(fp, "\t\t and ebx,byte 15\n"); else fprintf(fp, "\t\t and ebx,byte 7\n"); } fprintf(fp, "\t\t shr ecx,byte 9\n"); fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(Dest,Size,EBX,EAX,"-BCDSDB",SaveEDX); if (dir == 0) { if (type != 3) { fprintf(fp, "\t\t %s [%s+ECX*4],%s\n",Op ,REG_DAT ,Regname ) ; if (type == 4) SetFlags(Size,EAX,FALSE,TRUE,FALSE); else SetFlags(Size,EAX,FALSE,FALSE,FALSE); } else { if (Size == 'W') fprintf(fp, "\t\t cwde\n"); fprintf(fp, "\t\t %s [%s+ECX*4],EAX\n",Op ,REG_ADD); if (Op[0] == 'c') { SetFlags('L',EAX,FALSE,FALSE,FALSE); } } } else { fprintf(fp, "\t\t %s %s,[%s+ECX*4]\n", Op, Regname ,REG_DAT ) ; if (type == 4) SetFlags(Size,EAX,FALSE,TRUE,TRUE); else SetFlags(Size,EAX,FALSE,FALSE,TRUE); EffectiveAddressWrite(Dest,Size,EBX,FALSE,"---DS-B",FALSE); } Completed(); } OpcodeArray[Opcode] = BaseCode; } dir = SaveDir; } void typelogicalmath(void) { int dir, leng, mode, sreg ,reg ; for (reg = 0 ; reg < 8 ; reg++) { /* or */ for (dir = 0 ; dir < 2 ; dir++) for (leng = 0 ; leng < 3; leng++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dumpx( 0x8000, reg, 0, "or ", dir, leng, mode, sreg ) ; /* sub */ for (dir = 0 ; dir < 2 ; dir++) for (leng = 0 ; leng < 3; leng++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dumpx( 0x9000, reg, 4, "sub", dir, leng, mode, sreg ) ; /* suba */ for (dir = 0 ; dir < 2 ; dir++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dumpx( 0x9000, reg, 3, "sub", dir, 3, mode, sreg ) ; /* cmp */ for (leng = 0 ; leng < 3; leng++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dumpx( 0xb000, reg, 1, "cmp", 0, leng, mode, sreg ) ; /* cmpa */ for (dir = 0 ; dir < 2 ; dir++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dumpx( 0xb000, reg, 3, "cmp", dir, 3, mode, sreg ) ; /* adda */ for (dir = 0 ; dir < 2 ; dir++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dumpx( 0xd000, reg, 3, "add", dir, 3, mode, sreg ) ; /* eor */ for (leng = 0 ; leng < 3; leng++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dumpx( 0xb100, reg, 2, "xor", 1, leng, mode, sreg ) ; /* and */ for (dir = 0 ; dir < 2 ; dir++) for (leng = 0 ; leng < 3; leng++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dumpx( 0xc000, reg, 0, "and", dir, leng, mode, sreg ) ; /* add */ for (dir = 0 ; dir < 2 ; dir++) for (leng = 0 ; leng < 3; leng++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) dumpx( 0xd000, reg, 4, "add", dir, leng, mode, sreg ) ; } } /* * Single commands missed out by routines above * */ void mul(void) { int dreg, type, mode, sreg ; int Opcode, BaseCode ; int Dest ; char allow[] = "0-23456789ab-----" ; for (dreg = 0 ; dreg < 8 ; dreg++) for (type = 0 ; type < 2 ; type++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xc0c0 | (dreg<<9) | (type<<8) | (mode<<3) | sreg ; BaseCode = Opcode & 0xc1f8 ; if (mode == 7) { BaseCode |= sreg ; } Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0x0f] != '-') { if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 54 ; if (mode < 7) { fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); } fprintf(fp, "\t\t shr ecx, byte 9\n"); fprintf(fp, "\t\t and ecx, byte 7\n"); EffectiveAddressRead(Dest,'W',EBX,EAX,"ABCDSDB",FALSE); if (type == 0) fprintf(fp, "\t\t mul word [%s+ECX*4]\n",REG_DAT); else fprintf(fp, "\t\t imul word [%s+ECX*4]\n",REG_DAT); fprintf(fp, "\t\t shl edx, byte 16\n"); fprintf(fp, "\t\t mov dx,ax\n"); fprintf(fp, "\t\t mov [%s+ECX*4],edx\n",REG_DAT); SetFlags('L',EDX,TRUE,FALSE,FALSE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } void mull(void) { int mode, sreg ; int Opcode, BaseCode ; int Dest ; char allow[] = "0-23456789ab-----" ; char *Label = NULL ; for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x4c00 | (mode<<3) | sreg ; BaseCode = Opcode & 0x4c38 ; if (mode == 7) { BaseCode |= sreg ; } Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0x0f] != '-') { if (OpcodeArray[ BaseCode ] == -2) { TimingCycles += 70 ; Align(); Label = GenerateLabel(BaseCode,0); fprintf(fp, "%s:\n",Label); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (mode < 7) { fprintf(fp, "\t\t and ecx,byte 7\n"); } Memory_Fetch('W', EBX, FALSE ); // fetch the next word fprintf(fp, "\t\t add esi,byte 2\n\n"); EffectiveAddressRead(Dest,'L',ECX,EAX,"ABCDSDB",FALSE); // read from the EA fprintf(fp, "\t\t mov ecx,ebx\n"); // save 2nd word in ecx fprintf(fp, "\t\t shr ebx,12\n"); // ebx = Dl register fprintf(fp, "\t\t and ebx,7\n"); // 0-7 Label = GenerateLabel(BaseCode,1); fprintf(fp, "\t\t test ecx,0x0800\n"); // signed/unsigned? fprintf(fp, "\t\t jz short %s\n",Label); // skip if unsigned fprintf(fp, "\t\t imul dword [%s+EBX*4]\n",REG_DAT); // signed 32x32->64 fprintf(fp, "\t\t jmp short %s_1\n",Label); // skip fprintf(fp, "%s:\n",Label); fprintf(fp, "\t\t mul dword [%s+EBX*4]\n",REG_DAT); // unsigned 32x32->64 fprintf(fp, "%s_1:\n",Label); fprintf(fp, "\t\t mov [%s+EBX*4],eax\n",REG_DAT); // store Dl back fprintf(fp, "\t\t test ecx,0x0400\n"); // do we care? fprintf(fp, "\t\t jz short %s_2\n",Label); // if not, skip fprintf(fp, "\t\t and ecx,7\n"); // get Dh register fprintf(fp, "\t\t mov [%s+ECX*4],edx\n",REG_DAT); // store upper 32 bits SetFlags('L',EDX,TRUE,FALSE,FALSE); // set the flags fprintf(fp, "\t\t and edx,~0x0800\n"); // clear the overflow fprintf(fp, "\t\t jmp short %s_3\n",Label); // skip fprintf(fp, "%s_2:\n",Label); fprintf(fp, "\t\t mov ebx,edx\n"); // save upper 32 in ebx SetFlags('L',EAX,TRUE,FALSE,FALSE); // set the flags fprintf(fp, "\t\t sar eax,31\n"); // eax = sign-extended fprintf(fp, "\t\t test ecx,0x0800\n"); // signed/unsigned? fprintf(fp, "\t\t jnz short %s_4\n",Label); // skip if signed fprintf(fp, "\t\t xor eax,eax\n"); // always use 0 for unsigned fprintf(fp, "%s_4:\n",Label); fprintf(fp, "\t\t cmp eax,ebx\n"); // compare upper 32 against eax fprintf(fp, "\t\t je short %s_3\n",Label); // if equal to sign extension, skip fprintf(fp, "\t\t or edx,0x0800\n"); // set the overflow fprintf(fp, "%s_3:\n",Label); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } void divl(void) { int mode, sreg ; int Opcode, BaseCode ; int Dest ; char allow[] = "0-23456789ab-----" ; char *Label = NULL ; for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x4c40 | (mode<<3) | sreg ; BaseCode = Opcode & 0x4c78 ; if (mode == 7) { BaseCode |= sreg ; } Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0x0f] != '-') { if (OpcodeArray[ BaseCode ] == -2) { TimingCycles += 70 ; Align(); Label = GenerateLabel(BaseCode,0); fprintf(fp, "%s:\n",Label); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t push edx\n"); // save edx fprintf(fp, "\t\t add esi,byte 2\n\n"); fprintf(fp, "\t\t and ecx,byte 7\n"); // read from ea Memory_Fetch('W', EDX, FALSE ); // fetch 2nd word in ecx fprintf(fp, "\t\t add esi,byte 2\n\n"); EffectiveAddressRead(Dest,'L',ECX,EBX,"---DSDB",FALSE); fprintf(fp, "\t\t push esi\n"); // save and 0 esi ClearRegister(ESI); Label = GenerateLabel(BaseCode,1); fprintf(fp, "\t\t test ebx,ebx\n"); // check divisor against 0 fprintf(fp, "\t\t jz near %s_ZERO\n",Label); // handle divide-by-zero // low part always used fprintf(fp, "\t\t mov ecx,edx\n"); // ecx = extension word fprintf(fp, "\t\t shr edx,12\n"); // edx = Dq register fprintf(fp, "\t\t and edx,7\n"); // 0-7 fprintf(fp, "\t\t mov eax,[%s+edx*4]\n",REG_DAT); // eax = Dq register value ClearRegister(EDX); // edx = 0 fprintf(fp, "\t\t test ecx,0x0400\n"); // check size fprintf(fp, "\t\t jz short %s_1\n",Label); // skip if 32-bit dividend // high longword (64bit) fprintf(fp, "\t\t mov edx,ecx\n"); // edx = extension word fprintf(fp, "\t\t and edx,7\n"); // 0-7 fprintf(fp, "\t\t mov edx,[%s+edx*4]\n",REG_DAT); // fetch upper 32-bits fprintf(fp, "\t\t test ecx,0x0800\n"); // signed? fprintf(fp, "\t\t jz near %s_3\n",Label); // if not, skip to unsigned 64-bit fprintf(fp, "\t\t jmp near %s_2\n",Label); // skip to signed 64-bit case fprintf(fp, "%s_1:\n",Label); // short case ClearRegister(EDX); // clear edx fprintf(fp, "\t\t test ecx,0x0800\n"); // signed? fprintf(fp, "\t\t jz short %s_3\n",Label); // if not, don't convert fprintf(fp, "\t\t cdq\n"); // sign extend into edx // signed fprintf(fp, "%s_2:\n",Label); // signed 32/64-bit case fprintf(fp, "\t\t or esi,1\n"); // esi |= 1 to indicate signed fprintf(fp, "\t\t test ebx,ebx\n"); // check divisor sign fprintf(fp, "\t\t jge short %s_2b\n",Label); // if >= 0, don't set fprintf(fp, "\t\t or esi,2\n"); // esi |= 2 to indicate negative divisor fprintf(fp, "\t\t neg ebx\n"); // make positive fprintf(fp, "%s_2b:\n",Label); fprintf(fp, "\t\t test edx,edx\n"); // check dividend sign fprintf(fp, "\t\t jge short %s_3\n",Label); // if >= 0, don't set fprintf(fp, "\t\t push ebx\n"); // save ebx fprintf(fp, "\t\t push ecx\n"); // save ecx ClearRegister(EBX); // clear ebx ClearRegister(ECX); // clear ecx fprintf(fp, "\t\t sub ebx,eax\n"); // ebx = 0 - eax fprintf(fp, "\t\t sbb ecx,edx\n"); // ecx = 0 - edx fprintf(fp, "\t\t mov eax,ebx\n"); // eax = ebx fprintf(fp, "\t\t mov edx,ecx\n"); // edx = ecx fprintf(fp, "\t\t pop ecx\n"); // restore ecx fprintf(fp, "\t\t pop ebx\n"); // restore ebx fprintf(fp, "\t\t or esi,4\n"); // esi |= 4 to indicate negative dividend // unsigned fprintf(fp, "%s_3:\n",Label); // unsigned 32/64-bit case fprintf(fp, "\t\t cmp ebx,edx\n"); // check ebx against upper 32 bits fprintf(fp, "\t\t jbe near %s_OVERFLOW\n",Label); // generate overflow fprintf(fp, "\t\t div ebx\n"); // do the divide fprintf(fp, "\t\t test esi,esi\n"); // see if we need to post process fprintf(fp, "\t\t jz short %s_4\n",Label); // if not, skip fprintf(fp, "\t\t jpo short %s_4\n",Label); // if PO (pos*pos or neg*neg), leave the result fprintf(fp, "\t\t neg eax\n"); // negate the result // store results fprintf(fp, "%s_4:\n",Label); fprintf(fp, "\t\t mov ebx,ecx\n"); // ebx = extension word fprintf(fp, "\t\t and ebx,7\n"); // get Dr in ebx fprintf(fp, "\t\t shr ecx,12\n"); // ecx = Dq fprintf(fp, "\t\t and ecx,7\n"); // 0-7 fprintf(fp, "\t\t mov [%s+ebx*4],edx\n",REG_DAT); // store remainder first fprintf(fp, "\t\t mov [%s+ecx*4],eax\n",REG_DAT); // store quotient second fprintf(fp, "\t\t pop esi\n"); // restore esi fprintf(fp, "\t\t pop edx\n"); // restore edx SetFlags('L',EAX,TRUE,FALSE,FALSE); // set the flags fprintf(fp, "%s_5:\n",Label); fprintf(fp, "\t\t and edx,~1\n"); // clear the carry Completed(); fprintf(fp, "%s_ZERO:\t\t ;Do divide by zero trap\n", Label); /* Correct cycle counter for error */ fprintf(fp, "\t\t pop esi\n"); // restore esi fprintf(fp, "\t\t pop edx\n"); // restore edx fprintf(fp, "\t\t add dword [%s],byte %d\n",ICOUNT,95); fprintf(fp,"\t\t jmp short %s_5\n",Label); Exception(5,BaseCode); fprintf(fp, "%s_OVERFLOW:\n",Label); //set overflow fprintf(fp, "\t\t pop esi\n"); // restore esi fprintf(fp, "\t\t pop edx\n"); // restore edx fprintf(fp, "\t\t or edx,0x0800\n"); // set the overflow bit fprintf(fp, "\t\t jmp near %s_5\n",Label); // done } OpcodeArray[Opcode] = BaseCode ; } } } void bfext(void) { // just bfextu/bfexts for now char allow[] = "0-2--56789a-----" ; char *Label = NULL ; int mode,dreg,sign,Opcode,BaseCode,Dest ; for (mode=0; mode<8; mode++) for (dreg=0; dreg<8; dreg++) for (sign=0; sign<2; sign++) { Opcode = 0xe9c0 | (sign<<9) | (mode<<3) | dreg ; BaseCode = Opcode & 0xebf8 ; if (mode == 7) BaseCode |= dreg ; Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[BaseCode] == -2) { Align(); Label = GenerateLabel(BaseCode,0); fprintf(fp, "%s:\n",Label); Label = GenerateLabel(BaseCode,1); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (mode < 7) { fprintf(fp, "\t\t and ecx,byte 7\n"); } Memory_Fetch('W', EAX, FALSE ) ; fprintf(fp, "\t\t add esi,byte 2\n\n"); EffectiveAddressRead(Dest,'L',ECX,EDX,"ABCDSDB",FALSE); // edx = dword fprintf(fp, "\t\t mov ecx,eax\n"); fprintf(fp, "\t\t shr ecx,byte 6\n"); fprintf(fp, "\t\t test eax,0x0800\n"); fprintf(fp, "\t\t je short %s_1\n",Label); //get offset from Dx fprintf(fp, "\t\t and ecx,byte 7\n"); fprintf(fp, "\t\t mov ecx,[%s+ECX*4]\n",REG_DAT); //get offset from extension fprintf(fp, "%s_1:\n",Label); fprintf(fp, "\t\t and ecx,31\n"); // ecx = offset fprintf(fp, "\t\t mov ebx,eax\n"); fprintf(fp, "\t\t test eax,0x0020\n"); fprintf(fp, "\t\t je short %s_2\n",Label); //get width from Dy fprintf(fp, "\t\t and ebx,byte 7\n"); fprintf(fp, "\t\t mov ebx,[%s+EBX*4]\n",REG_DAT); //get width from extension fprintf(fp, "%s_2:\n",Label); //fix 0=32 fprintf(fp, "\t\t sub ebx,byte 1\n"); fprintf(fp, "\t\t and ebx,byte 31\n"); fprintf(fp, "\t\t add ebx,byte 1\n"); // ebx = width fprintf(fp, "\t\t rol edx,cl\n"); // check for N fprintf(fp, "\t\t mov ecx,32\n"); fprintf(fp, "\t\t sub ecx,ebx\n"); fprintf(fp, "\t\t mov ebx,edx\n"); SetFlags('L',EBX,TRUE,FALSE,FALSE); if (sign) fprintf(fp, "\t\t sar ebx,cl\n"); else fprintf(fp, "\t\t shr ebx,cl\n"); fprintf(fp, "\t\t shr eax,12\n"); fprintf(fp, "\t\t and eax,7\n"); fprintf(fp, "\t\t mov [%s+EAX*4],ebx\n",REG_DAT); fprintf(fp, "\t\t test ebx,ebx\n"); fprintf(fp, "\t\t jnz short %s_3\n",Label); //zero flag fprintf(fp, "\t\t or edx,40h\n"); fprintf(fp, "%s_3:\n",Label); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * not * clr * neg * negx * */ void not(void) { int type,leng, mode, sreg ; int Opcode, BaseCode ; int Dest ; int SaveEDX=0; char Size=' ' ; char * Regname="" ; char * RegnameECX ; char * Label; char allow[] = "0-2345678-------" ; for (type = 0 ; type < 4 ; type++) for (leng = 0 ; leng < 3 ; leng++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x4000 | (type<<9) | (leng<<6) | (mode<<3) | sreg ; BaseCode = Opcode & 0x46f8 ; if (mode == 7) { BaseCode |= sreg ; } // A7+, A7- #ifdef A7ROUTINE if ((leng == 0) && (sreg == 7) && (mode > 2) && (mode < 5)) { BaseCode |= sreg ; } #endif Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0x0f] != '-') { switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameECX = regnamesshort[ECX]; break; case 1: Size = 'W'; Regname = regnamesword[0]; RegnameECX = regnamesword[ECX]; break; case 2: Size = 'L'; Regname = regnameslong[0]; RegnameECX = regnameslong[ECX]; break; } if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (Size != 'L') TimingCycles += 4; else TimingCycles += 6; if (Dest < 7) fprintf(fp, "\t\t and ecx,byte 7\n"); if (type == 0) SaveEDX = TRUE; else SaveEDX = FALSE; /* CLR does not need to read source (although it does on a real 68000) */ if (type != 1) { EffectiveAddressRead(Dest,Size,ECX,EAX,"A-CDS-B",SaveEDX); } switch (type) { case 0: /* negx */ /* Preserve old Z flag */ fprintf(fp, "\t\t mov ebx,edx\n"); CopyX(); fprintf(fp, "\t\t adc %s,byte 0\n", Regname ) ; fprintf(fp, "\t\t neg %s\n", Regname ) ; /* Set the Flags */ SetFlags(Size,EAX,FALSE,TRUE,FALSE); /* Handle the Z flag */ Label = GenerateLabel(0,1); fprintf(fp, "\t\t jnz short %s\n\n",Label); fprintf(fp, "\t\t and edx,byte -65 ; Remove Z\n"); fprintf(fp, "\t\t and ebx,byte 40h ; Mask out Old Z\n"); fprintf(fp, "\t\t or edx,ebx ; Copy across\n\n"); fprintf(fp, "%s:\n",Label); break; case 1: /* clr */ ClearRegister(EAX); EffectiveAddressWrite(Dest,Size,ECX,TRUE,"----S-B",FALSE); fprintf(fp, "\t\t mov edx,40H\n"); break; case 2: /* neg */ fprintf(fp, "\t\t neg %s\n",Regname ) ; SetFlags(Size,EAX,FALSE,TRUE,TRUE); break; case 3: /* not */ fprintf(fp, "\t\t xor %s,-1\n",Regname ) ; SetFlags(Size,EAX,FALSE,FALSE,TRUE); break; } /* Update (unless CLR command) */ if (type != 1) EffectiveAddressWrite(Dest,Size,ECX,FALSE,"---DS-B",TRUE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * Move to/from USP * */ void moveusp(void) { int Opcode, BaseCode ; int dir, sreg ; char * Label; for (dir = 0 ; dir < 2 ; dir++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x4e60 | ( dir << 3 ) | sreg ; BaseCode = Opcode & 0x4e68 ; if (OpcodeArray[BaseCode] == -2) { Align(); Label = GenerateLabel(BaseCode,0); fprintf(fp, "%s\n", Label ); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 4; fprintf(fp, "\t\t test byte [%s],20h \t\t\t; Supervisor Mode ?\n",REG_SRH); fprintf(fp, "\t\t jz short OP%d_%4.4x_Trap\n",CPU,BaseCode); fprintf(fp, "\t\t and ecx,7\n"); if (dir == 0) /* reg 2 USP */ { fprintf(fp, "\t\t mov eax,[%s+ECX*4]\n",REG_ADD); fprintf(fp, "\t\t mov [%s],eax\n",REG_USP); } else { fprintf(fp, "\t\t mov eax,[%s]\n",REG_USP); fprintf(fp, "\t\t mov [%s+ECX*4],eax\n",REG_ADD); } Completed(); fprintf(fp, "OP%d_%4.4x_Trap:\n",CPU,BaseCode); Exception(8,BaseCode); } OpcodeArray[Opcode] = BaseCode ; } } /* * Check * */ void chk(void) { int dreg,mode,sreg,size ; int Opcode, BaseCode ; int Dest ; char * Label ; char *allow = "0-23456789ab----" ; for (size = 0 ; size < (CPU==2 ? 2 : 1); size++) for (dreg = 0 ; dreg < 8; dreg++) for (mode = 0 ; mode < 8; mode++) for (sreg = 0 ; sreg < 8; sreg++) { if (size == 0) /* word */ Opcode = 0x4180 | (dreg<<9) | (mode<<3) | sreg ; else /* long */ Opcode = 0x4100 | (dreg<<9) | (mode<<3) | sreg ; BaseCode = Opcode & 0x41f8 ; if (mode == 7) { BaseCode |= sreg ; } Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[BaseCode] == -2) { Align(); Label = GenerateLabel(BaseCode,0); fprintf(fp, "%s:\n", Label ); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 10; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t shr ebx,byte 9\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); if (Dest < 7) fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(Dest,(size == 0) ? 'W' : 'L',ECX,EAX,"----S-B",FALSE); if (size == 0) /* word */ { fprintf(fp, "\t\t movsx ebx,word [%s+EBX*4]\n",REG_DAT); fprintf(fp, "\t\t movsx eax,ax\n"); } else /* long */ fprintf(fp, "\t\t mov ebx,[%s+EBX*4]\n",REG_DAT); fprintf(fp, "\t\t test ebx,ebx\n"); /* is word bx < 0 */ fprintf(fp, "\t\t jl near OP%d_%4.4x_Trap_minus\n",CPU,BaseCode); fprintf(fp, "\t\t cmp ebx,eax\n"); fprintf(fp, "\t\t jg near OP%d_%4.4x_Trap_over\n",CPU,BaseCode); Completed(); /* N is set if data less than zero */ Align(); fprintf(fp, "OP%d_%4.4x_Trap_minus:\n",CPU,BaseCode); fprintf(fp, "\t\t or edx,0x0080\n"); /* N flag = 80H */ fprintf(fp, "\t\t jmp short OP%d_%4.4x_Trap_Exception\n",CPU,BaseCode); /* N is cleared if greated than compared number */ Align(); fprintf(fp, "OP%d_%4.4x_Trap_over:\n",CPU,BaseCode); fprintf(fp, "\t\t and edx,0x007f\n"); /* N flag = 80H */ fprintf(fp, "OP%d_%4.4x_Trap_Exception:\n",CPU,BaseCode); fprintf(fp, "\t\t mov al,6\n"); Exception(-1,0x10000+BaseCode); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } void chk2(void) { #if 0 int mode,sreg,size ; int Opcode, BaseCode ; int Dest ; char * Label ; char *allow = "--2--56789a-----" ; for (size = 0 ; size < 2; size++) for (mode = 0 ; mode < 8; mode++) for (sreg = 0 ; sreg < 8; sreg++) { Opcode = 0x00c0 | (size<<9) | (mode<<3) | sreg; BaseCode = Opcode & 0xfff8 ; if (mode == 7) { BaseCode |= sreg ; } Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[BaseCode] == -2) { Align(); Label = GenerateLabel(BaseCode,0); fprintf(fp, "%s:\n", Label ); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 10; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t shr ebx,byte 9\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); if (Dest < 7) fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(Dest,'W',ECX,EAX,"----S-B",FALSE); if (size == 0) /* word */ { fprintf(fp, "\t\t movsx ebx,word [%s+EBX*4]\n",REG_DAT); fprintf(fp, "\t\t movsx eax,ax\n"); } else /* long */ fprintf(fp, "\t\t mov ebx,[%s+EBX*4]\n",REG_DAT); fprintf(fp, "\t\t test ebx,ebx\n"); /* is word bx < 0 */ fprintf(fp, "\t\t jl near OP%d_%4.4x_Trap_minus\n",CPU,BaseCode); fprintf(fp, "\t\t cmp ebx,eax\n"); fprintf(fp, "\t\t jg near OP%d_%4.4x_Trap_over\n",CPU,BaseCode); Completed(); /* N is set if data less than zero */ Align(); fprintf(fp, "OP%d_%4.4x_Trap_minus:\n",CPU,BaseCode); fprintf(fp, "\t\t or edx,0x0080\n"); /* N flag = 80H */ fprintf(fp, "\t\t jmp short OP%d_%4.4x_Trap_Exception\n",CPU,BaseCode); /* N is cleared if greated than compared number */ Align(); fprintf(fp, "OP%d_%4.4x_Trap_over:\n",CPU,BaseCode); fprintf(fp, "\t\t and edx,0x007f\n"); /* N flag = 80H */ fprintf(fp, "OP%d_%4.4x_Trap_Exception:\n",CPU,BaseCode); fprintf(fp, "\t\t mov al,6\n"); Exception(-1,0x10000+BaseCode); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } #endif } /* * Load Effective Address */ void LoadEffectiveAddress(void) { int Opcode, BaseCode ; int sreg,mode,dreg ; int Dest ; char allow[] = "--2--56789a-----" ; for (sreg = 0 ; sreg < 8 ; sreg++) for (mode = 0 ; mode < 8 ; mode++) for (dreg = 0 ; dreg < 8 ; dreg++) { Opcode = 0x41c0 | (sreg<<9) | (mode<<3) | dreg ; BaseCode = Opcode & 0x41f8 ; if (mode == 7) BaseCode = BaseCode | dreg ; Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0x0f] != '-') { if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); switch (mode) { case 2: TimingCycles += 4; break; case 5: case 7: case 9: TimingCycles += 8; break; case 6: case 8: case 10: TimingCycles += 12; break; } if (mode < 7) { fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); } fprintf(fp, "\t\t shr ecx,byte 9\n"); fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressCalculate(Dest,'L',EBX,TRUE); fprintf(fp, "\t\t mov [%s+ECX*4],edi\n",REG_ADD); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * Negate BCD * */ void nbcd(void) { int Opcode, BaseCode ; int sreg,mode,Dest ; char allow[] = "0-2345678-------" ; for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x4800 | (mode<<3) | sreg ; BaseCode = Opcode & 0x4838 ; if (mode == 7) BaseCode |= sreg ; // A7+, A7- #ifdef A7ROUTINE if ((sreg == 7) && (mode > 2) && (mode < 5)) { BaseCode |= sreg; } #endif Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (mode < 2) TimingCycles += 6; else TimingCycles += 8; fprintf(fp, "\t\t and ecx, byte 7\n"); EffectiveAddressRead(Dest,'B',ECX,EBX,"--C-SDB",FALSE); ClearRegister(EAX); CopyX(); fprintf(fp, "\t\t sbb al,bl\n"); fprintf(fp, "\t\t das\n"); SetFlags('B',EAX,FALSE,TRUE,TRUE); EffectiveAddressWrite(Dest,'B',ECX,EAX,"----S-B",FALSE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } void tas(void) { int Opcode, BaseCode ; int sreg,mode,Dest ; char allow[] = "0-2345678-------" ; for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x4ac0 | (mode<<3) | sreg ; BaseCode = Opcode & 0x4af8 ; if (mode == 7) BaseCode |= sreg ; #ifdef A7ROUTINE if ((sreg == 7) && (mode > 2) && (mode < 5)) { BaseCode |= sreg ; } #endif Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (mode < 2) TimingCycles += 4; else TimingCycles += 14; fprintf(fp, "\t\t and ecx, byte 7\n"); EffectiveAddressRead(Dest,'B',ECX,EAX,"--C-SDB",FALSE); SetFlags('B',EAX,TRUE,FALSE,TRUE); fprintf(fp, "\t\t or al,128\n"); EffectiveAddressWrite(Dest,'B',ECX,EAX,"----S-B",FALSE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * push Effective Address */ void PushEffectiveAddress(void) { int Opcode, BaseCode ; int mode,dreg ; int Dest ; char allow[] = "--2--56789a-----" ; for (mode = 0 ; mode < 8 ; mode++) for (dreg = 0 ; dreg < 8 ; dreg++) { Opcode = 0x4840 | (mode<<3) | dreg ; BaseCode = Opcode & 0x4878 ; if (mode == 7) BaseCode = BaseCode | dreg ; Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0x0f] != '-') { if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); switch (mode) { case 2: TimingCycles += 12; break; case 5: case 7: case 9: TimingCycles += 16; break; case 6: case 8: case 10: TimingCycles += 20; break; } if (mode < 7) { fprintf(fp, "\t\t and ecx,byte 7\n"); } EffectiveAddressCalculate(Dest,'L',ECX,TRUE); fprintf(fp, "\t\t mov ecx,[%s]\t ; Push onto Stack\n",REG_A7); fprintf(fp, "\t\t sub ecx,byte 4\n"); fprintf(fp, "\t\t mov [%s],ecx\n",REG_A7); Memory_Write('L',ECX,EDI,"---DS-B",2); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * Test * */ void tst(void) { int leng, mode, sreg ; int Opcode, BaseCode ; int Dest ; char Size=' ' ; char * Regname ; char * RegnameECX ; char allow[] = "0-2345678-------" ; if (CPU==2) allow[1] = '1'; for (leng = 0 ; leng < 3 ; leng++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x4a00 | (leng<<6) | (mode<<3) | sreg ; BaseCode = Opcode & 0x4af8 ; if (mode == 7) { BaseCode |= sreg ; } // A7+, A7- #ifdef A7ROUTINE if ((leng == 0) && (sreg == 7) && (mode > 2) && (mode < 5)) { BaseCode |= sreg ; } #endif Dest = EAtoAMN(Opcode, FALSE); if ((allow[Dest&0x0f] != '-') || (( mode == 1 ) && (leng != 0))) { switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameECX = regnamesshort[ECX]; break; case 1: Size = 'W'; Regname = regnamesword[0]; RegnameECX = regnamesword[ECX]; break; case 2: Size = 'L'; Regname = regnameslong[0]; RegnameECX = regnameslong[ECX]; break; } if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 4; if (Dest < 7) fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(Dest,Size,ECX,EAX,"----S-B",FALSE); SetFlags(Size,EAX,TRUE,FALSE,FALSE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * Move registers too / from memory * */ void movem_reg_ea(void) { int leng,mode,sreg ; int Opcode, BaseCode ; int Dest ; char Size ; char * Label ; char *allow = "--2-45678-------" ; for (leng = 0 ; leng < 2; leng++) for (mode = 0 ; mode < 8; mode++) for (sreg = 0 ; sreg < 8; sreg++) { Opcode = 0x4880 | ( leng<<6) | (mode<<3) | sreg ; BaseCode = Opcode & 0x4cf8 ; if (mode == 7) { BaseCode |= sreg ; } Dest = EAtoAMN(Opcode, FALSE); Size = "WL"[leng] ; if (allow[Dest&0xf] != '-') { if (OpcodeArray[BaseCode] == - 2) { Align(); Label = GenerateLabel(BaseCode,0); fprintf(fp, "%s:\n",Label ) ; SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); switch (mode) { case 2: case 4: TimingCycles += 8 ; break; case 5: case 7: TimingCycles += 12 ; break; case 6: case 8: TimingCycles += 14 ; break; } fprintf(fp, "\t\t push edx\n"); Memory_Fetch('W',EDX,FALSE); fprintf(fp, "\t\t add esi,byte 2\n"); if (mode < 7) { fprintf(fp, "\t\t and ecx,byte 7\n"); } if (mode == 4) { fprintf(fp, "\t\t push ecx\n"); fprintf(fp, "\t\t mov edi,[%s+ECX*4]\n",REG_ADD); } else EffectiveAddressCalculate(Dest,'L',ECX,TRUE); fprintf(fp, "\t\t mov ebx,1\n"); /* predecrement uses d0-d7..a0-a7 a7 first*/ /* other modes use a7-a0..d7-d0 d0 first*/ if (Dest != 4) ClearRegister(ECX); else fprintf(fp, "\t\t mov ecx,3Ch\n"); fprintf(fp, "OP%d_%4.4x_Again:\n",CPU,BaseCode); fprintf(fp, "\t\t test edx,ebx\n"); fprintf(fp, "\t\t je OP%d_%4.4x_Skip\n",CPU,BaseCode); fprintf(fp, "\t\t mov eax,[%s+ecx]\n",REG_DAT); /* load eax with current reg data */ if (Dest == 4) { if (Size == 'W') /* adjust pointer before write */ fprintf(fp, "\t\t sub edi,byte 2\n"); else fprintf(fp, "\t\t sub edi,byte 4\n"); } Memory_Write(Size,EDI,EAX,"-BCDSDB",1); if (Dest != 4) { if (Size == 'W') /* adjust pointer after write */ fprintf(fp, "\t\t add edi,byte 2\n"); else fprintf(fp, "\t\t add edi,byte 4\n"); } /* Update Cycle Count */ if (Size == 'W') fprintf(fp, "\t\t sub dword [%s],byte 4\n",ICOUNT); else fprintf(fp, "\t\t sub dword [%s],byte 8\n",ICOUNT); fprintf(fp, "OP%d_%4.4x_Skip:\n",CPU,BaseCode); if (Dest != 4) fprintf(fp, "\t\t add ecx,byte 4h\n"); else fprintf(fp, "\t\t sub ecx,byte 4h\n"); fprintf(fp, "\t\t add ebx,ebx\n"); /* faster than shl ebx,1 */ fprintf(fp, "\t\t test bx,bx\n"); /* check low 16 bits */ fprintf(fp, "\t\t jnz OP%d_%4.4x_Again\n",CPU,BaseCode); if (Dest == 4) { fprintf(fp, "\t\t pop ecx\n"); fprintf(fp, "\t\t mov [%s+ECX*4],edi\n",REG_ADD); } fprintf(fp, "\t\t pop edx\n"); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } void movem_ea_reg(void) { int leng,mode,sreg ; int Opcode, BaseCode ; int Dest ; char Size ; char * Label ; char *allow = "--23-56789a-----" ; for (leng = 0 ; leng < 2; leng++) for (mode = 0 ; mode < 8; mode++) for (sreg = 0 ; sreg < 8; sreg++) { Opcode = 0x4c80 | ( leng<<6) | (mode<<3) | sreg ; BaseCode = Opcode & 0x4cf8 ; if (mode == 7) { BaseCode |= sreg ; } Dest = EAtoAMN(Opcode, FALSE); Size = "WL"[leng] ; if (allow[Dest&0xf] != '-') { if (OpcodeArray[BaseCode] == - 2) { Align(); Label = GenerateLabel(BaseCode,0); fprintf(fp, "%s:\n",Label ) ; SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); switch (mode) { case 2: case 4: TimingCycles += 8 ; break; case 5: case 7: TimingCycles += 12 ; break; case 6: case 8: TimingCycles += 14 ; break; } fprintf(fp, "\t\t push edx\n"); /* save edx because sr is unaffected */ Memory_Fetch('W',EDX,FALSE); fprintf(fp, "\t\t add esi,byte 2\n"); if (mode < 7) { fprintf(fp, "\t\t and ecx,byte 7\n"); } if (mode == 3) fprintf(fp, "\t\t push ecx\n"); /* if (An)+ then it needed later */ EffectiveAddressCalculate(Dest,'L',ECX,TRUE); fprintf(fp, "\t\t mov ebx,1\n"); /* setup register list mask */ /* predecrement uses d0-d7..a0-a7 a7 first*/ /* other modes use a7-a0..d7-d0 d0 first*/ ClearRegister(ECX); /* always start with D0 */ fprintf(fp, "OP%d_%4.4x_Again:\n",CPU,BaseCode); fprintf(fp, "\t\t test edx,ebx\n"); /* is bit set for this register? */ fprintf(fp, "\t\t je OP%d_%4.4x_Skip\n",CPU,BaseCode); Memory_Read(Size,EDI,"-BCDSDB",1); if (Size == 'W') fprintf(fp, "\t\t cwde\n"); /* word size must be sign extended */ fprintf(fp, "\t\t mov [%s+ecx],eax\n",REG_DAT); /* load current reg with eax */ if (Size == 'W') /* adjust pointer after write */ fprintf(fp, "\t\t add edi,byte 2\n"); else fprintf(fp, "\t\t add edi,byte 4\n"); /* Update Cycle Count */ if (Size == 'W') fprintf(fp, "\t\t sub dword [%s],byte 4\n",ICOUNT); else fprintf(fp, "\t\t sub dword [%s],byte 8\n",ICOUNT); fprintf(fp, "OP%d_%4.4x_Skip:\n",CPU,BaseCode); fprintf(fp, "\t\t add ecx,byte 4\n"); /* adjust pointer to next reg */ fprintf(fp, "\t\t add ebx,ebx\n"); /* Faster than shl ebx,1 */ fprintf(fp, "\t\t test bx,bx\n"); /* check low 16 bits */ fprintf(fp, "\t\t jnz OP%d_%4.4x_Again\n",CPU,BaseCode); if (mode == 3) { fprintf(fp, "\t\t pop ecx\n"); fprintf(fp, "\t\t mov [%s+ECX*4],edi\n",REG_ADD); /* reset Ax if mode = (Ax)+ */ } fprintf(fp, "\t\t pop edx\n"); /* restore flags */ Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * Link / Unlink * * Local stack space * */ void link(void) { int sreg ; int Opcode, BaseCode ; for (sreg = 0 ; sreg < 8; sreg++) { Opcode = 0x4e50 | sreg ; BaseCode = 0x4e50 ; if (OpcodeArray[BaseCode] == - 2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 16; fprintf(fp, "\t\t sub dword [%s],byte 4\n",REG_A7); fprintf(fp, "\t\t and ecx, byte 7\n"); fprintf(fp, "\t\t mov eax,[%s+ECX*4]\n",REG_ADD); fprintf(fp, "\t\t mov edi,[%s]\n",REG_A7); fprintf(fp, "\t\t mov [%s+ECX*4],edi\n",REG_ADD); Memory_Write('L',EDI,EAX,"---DS-B",1); Memory_Fetch('W',EAX,TRUE); fprintf(fp, "\t\t add esi,byte 2\n"); fprintf(fp, "\t\t add [%s],eax\n",REG_A7); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void unlinkasm(void) { int sreg ; int Opcode, BaseCode ; for (sreg = 0 ; sreg < 8; sreg++) { Opcode = 0x4e58 | sreg ; BaseCode = 0x4e58 ; if (OpcodeArray[BaseCode] == - 2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 12; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx, byte 7\n"); fprintf(fp, "\t\t mov edi,[%s+EBX*4]\n",REG_ADD); Memory_Read('L',EDI,"-B-DSDB",1); fprintf(fp, "\t\t mov [%s+EBX*4],eax\n",REG_ADD); fprintf(fp, "\t\t add edi,byte 4\n"); fprintf(fp, "\t\t mov dword [%s],EDI\n",REG_A7); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void trap(void) { int Count; int BaseCode = 0x4E40; if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); fprintf(fp, "\t\t mov eax,ecx\n"); fprintf(fp, "\t\t and eax,byte 15\n"); fprintf(fp, "\t\t or eax,byte 32\n"); Exception(-1,BaseCode); Completed(); } for (Count=0;Count<=15;Count++) OpcodeArray[BaseCode+Count] = BaseCode; } void reset(void) { int BaseCode = 0x4E70; char * Label; if (OpcodeArray[BaseCode] == -2) { Align(); Label = GenerateLabel(BaseCode,0); TimingCycles += 132; fprintf(fp, "%s:\n", Label ); SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); fprintf(fp, "\t\t test byte [%s],20h \t\t\t; Supervisor Mode ?\n",REG_SRH); fprintf(fp, "\t\t jnz near OP%d_%4.4x_RESET\n",CPU,BaseCode); Exception(8,BaseCode); fprintf(fp, "\nOP%d_%4.4x_RESET:\n",CPU,BaseCode); /* Prefetch next instruction */ if(CPU==2) { /* 32 bit memory version */ fprintf(fp, "\t\t xor esi,2\n"); /* ASG */ #ifdef STALLCHECK ClearRegister(ECX); fprintf(fp, "\t\t mov cx,[esi+ebp]\n"); #else fprintf(fp, "\t\t movzx ecx,word [esi+ebp]\n"); #endif fprintf(fp, "\t\t xor esi,2\n"); /* ASG */ } else { /* 16 bit memory */ #ifdef STALLCHECK ClearRegister(ECX); fprintf(fp, "\t\t mov cx,[esi+ebp]\n"); #else fprintf(fp, "\t\t movzx ecx,word [esi+ebp]\n"); #endif } fprintf(fp, "\t\t mov eax,dword [%s]\n", REG_RESET_CALLBACK); fprintf(fp, "\t\t test eax,eax\n"); fprintf(fp, "\t\t jz near OP%d_%4.4x_END\n",CPU,BaseCode); /* Callback for Reset */ fprintf(fp, "\t\t mov [%s],ESI,\n",REG_PC); fprintf(fp, "\t\t mov [%s],edx\n",REG_CCR); fprintf(fp, "\t\t push ECX\n"); fprintf(fp, "\t\t call eax\n"); fprintf(fp, "\t\t mov ESI,[%s]\n",REG_PC); fprintf(fp, "\t\t mov edx,[%s]\n",REG_CCR); fprintf(fp, "\t\t pop ECX\n"); fprintf(fp, "\t\t mov ebp,dword [%sOP_ROM]\n", PREF); fprintf(fp, "OP%d_%4.4x_END:\n",CPU,BaseCode); fprintf(fp, "\t\t sub dword [%s],%d\n",ICOUNT,TimingCycles); fprintf(fp, "\t\t jmp [%s_OPCODETABLE+ecx*4]\n\n", CPUtype); } OpcodeArray[BaseCode] = BaseCode ; } void nop(void) { int BaseCode = 0x4e71 ; if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 4; Completed(); OpcodeArray[BaseCode] = BaseCode ; } } void stop(void) { char TrueLabel[16]; int BaseCode = 0x4e72 ; if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 4; /* Must be in Supervisor Mode */ sprintf(TrueLabel,GenerateLabel(0,1)); fprintf(fp, "\t\t test byte [%s],20h \t\t\t; Supervisor Mode ?\n",REG_SRH); fprintf(fp, "\t\t je near %s\n\n",TrueLabel); /* Next WORD is new SR */ Memory_Fetch('W',EAX,FALSE); fprintf(fp, "\t\t add esi,byte 2\n"); WriteCCR('W'); /* See if Valid interrupt waiting */ CheckInterrupt = 0; fprintf(fp, "\t\t mov eax,[%s]\n",REG_IRQ); fprintf(fp, "\t\t and eax,byte 07H\n"); fprintf(fp, "\t\t cmp al,7\t\t ; Always take 7\n"); fprintf(fp, "\t\t je near procint\n\n"); fprintf(fp, "\t\t mov ebx,[%s]\t\t; int mask\n",REG_SRH); fprintf(fp, "\t\t and ebx,byte 07H\n"); fprintf(fp, "\t\t cmp eax,ebx\n"); fprintf(fp, "\t\t jg near procint\n\n"); /* No int waiting - clear count, set stop */ ClearRegister(ECX); fprintf(fp, "\t\t mov [%s],ecx\n",ICOUNT); fprintf(fp, "\t\t or byte [%s],80h\n",REG_IRQ); Completed(); /* User Mode - Exception */ Align(); fprintf(fp, "%s:\n",TrueLabel); Exception(8,BaseCode); OpcodeArray[BaseCode] = BaseCode ; } } void ReturnFromException(void) { char TrueLabel[16]; int BaseCode = 0x4e73; Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 20; /* Check in Supervisor Mode */ sprintf(TrueLabel,GenerateLabel(0,1)); fprintf(fp, "\t\t test byte [%s],20h \t\t\t; Supervisor Mode ?\n",REG_SRH); fprintf(fp, "\t\t je near %s\n\n",TrueLabel); /* Get SR - Save in EBX */ fprintf(fp, "\t\t mov edi,[%s]\n",REG_A7); fprintf(fp, "\t\t add dword [%s],byte 6\n",REG_A7); Memory_Read('W',EDI,"-----DB",2); fprintf(fp, "\t\t add edi,byte 2\n"); fprintf(fp, "\t\t mov esi,eax\n"); /* Get PC */ Memory_Read('L',EDI,"----S-B",0); fprintf(fp, "\t\t xchg esi,eax\n"); /* Update CCR (and A7) */ WriteCCR('W'); MemoryBanking(BaseCode); Completed(); fprintf(fp, "%s:\n",TrueLabel); Exception(8,0x10000+BaseCode); OpcodeArray[BaseCode] = BaseCode; } void trapv(void) { int BaseCode = 0x4E76; char * Label; if (OpcodeArray[BaseCode] == -2) { Align(); Label = GenerateLabel(BaseCode,0); fprintf(fp, "%s\n", Label ); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 4; fprintf(fp, "\t\t test dh,08h\n"); fprintf(fp, "\t\t jz near OP%d_%4.4x_Clear\n",CPU,BaseCode); Exception(7,BaseCode); fprintf(fp, "OP%d_%4.4x_Clear:\n",CPU,BaseCode); Completed(); } OpcodeArray[BaseCode] = BaseCode ; } void illegal_opcode(void) { Align(); fprintf(fp, "ILLEGAL:\n"); fprintf(fp, "\t\t mov [%sillegal_op],ecx\n", PREF); fprintf(fp, "\t\t mov [%sillegal_pc],esi\n", PREF); #if 0 #ifdef MAME_DEBUG fprintf(fp, "\t\t jmp ecx\n"); fprintf(fp, "\t\t pushad\n"); fprintf(fp, "\t\t call %sm68k_illegal_opcode\n", PREF); fprintf(fp, "\t\t popad\n"); #endif #endif Exception(4,0xFFFE); } /* * Return from subroutine * restoring flags as well * */ void ReturnandRestore(void) { int BaseCode = 0x4e77; Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 20; /* Get SR into ESI */ fprintf(fp, "\t\t mov edi,[%s]\n",REG_A7); fprintf(fp, "\t\t add dword [%s],byte 6\n",REG_A7); Memory_Read('W',EDI,"-----DB",2); fprintf(fp, "\t\t add edi,byte 2\n"); fprintf(fp, "\t\t mov esi,eax\n"); /* Get PC */ Memory_Read('L',EDI,"----SDB",0); fprintf(fp, "\t\t xchg esi,eax\n"); /* Update flags */ WriteCCR('B'); MemoryBanking(BaseCode); Completed(); OpcodeArray[BaseCode] = BaseCode; } /* * Return from Subroutine * */ void rts(void) { int BaseCode = 0x4e75 ; if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); SavePreviousPC(); TimingCycles += 16; OpcodeArray[BaseCode] = BaseCode ; fprintf(fp, "\t\t mov eax,[%s]\n",REG_A7); fprintf(fp, "\t\t add dword [%s],byte 4\n",REG_A7); Memory_Read('L',EAX,"---D--B",1); fprintf(fp, "\t\t mov esi,eax\n"); MemoryBanking(BaseCode); Completed(); } } void jmp_jsr(void) { int Opcode, BaseCode ; int dreg,mode,type ; int Dest ; char allow[] = "--2--56789a-----" ; for (type = 0 ; type < 2 ; type++) for (mode = 0 ; mode < 8 ; mode++) for (dreg = 0 ; dreg < 8 ; dreg++) { Opcode = 0x4e80 | (type<<6) | (mode<<3) | dreg ; BaseCode = Opcode & 0x4ef8 ; if (mode == 7) BaseCode = BaseCode | dreg ; Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0x0f] != '-') { if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); switch (mode) { case 2: TimingCycles += 8; break; case 5: case 7: case 9: TimingCycles += 10; break; case 8: TimingCycles += 12; break; case 6: case 10: TimingCycles += 14; break; } if (type == 0) /* jsr takes 8 more than jmp */ TimingCycles += 8; if (mode < 7) { fprintf(fp, "\t\t and ecx,byte 7\n"); } EffectiveAddressCalculate(Dest,'L',ECX,TRUE); /* jsr needs to push PC onto stack */ if (type == 0) { PushPC(EBX,EAX,"---D-DB",1); } fprintf(fp, "\t\t mov esi,edi\n"); MemoryBanking(BaseCode); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } void cmpm(void) { int Opcode, BaseCode ; int regx,leng,regy ; int ModeModX, ModeModY; char Size=' ' ; char * Regname="" ; char * RegnameEBX="" ; for (regx = 0 ; regx < 8 ; regx++) for (leng = 0 ; leng < 3 ; leng++) for (regy = 0 ; regy < 8 ; regy++) { Opcode = 0xb108 | (regx<<9) | (leng<<6) | regy ; BaseCode = Opcode & 0xb1c8 ; ModeModX = 0; ModeModY = 0; #ifdef A7ROUTINE if (leng==0) { if (regx==7) { BaseCode |= (regx<<9); ModeModX = 16; } if (regy==7) { BaseCode |= regy; ModeModY = 16; } } #endif switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[EAX]; RegnameEBX = regnamesshort[EBX]; break; case 1: Size = 'W'; Regname = regnamesword[EAX]; RegnameEBX = regnamesword[EBX]; break; case 2: Size = 'L'; Regname = regnameslong[EAX]; RegnameEBX = regnameslong[EBX]; break; } if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); AddEACycles = 0 ; if (Size != 'L') TimingCycles += 12 ; else TimingCycles += 20 ; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx, byte 7\n"); fprintf(fp, "\t\t shr ecx, byte 9\n"); fprintf(fp, "\t\t and ecx, byte 7\n"); EffectiveAddressRead(3+ModeModY,Size,EBX,EBX,"--C-S-B",FALSE); EffectiveAddressRead(3+ModeModX,Size,ECX,EAX,"-B--S-B",FALSE); fprintf(fp, "\t\t cmp %s,%s\n",Regname,RegnameEBX); SetFlags(Size,EAX,FALSE,FALSE,FALSE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void exg(void) { int Opcode, BaseCode ; int regx,type,regy ; int opmask[3] = { 0x08, 0x09, 0x11} ; for (regx = 0 ; regx < 8 ; regx++) for (type = 0 ; type < 3 ; type++) for (regy = 0 ; regy < 8 ; regy++) { Opcode = 0xc100 | (regx<<9) | (opmask[type]<<3) | regy ; BaseCode = Opcode & 0xc1c8 ; if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 6 ; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); fprintf(fp, "\t\t shr ecx,byte 9\n"); fprintf(fp, "\t\t and ecx,byte 7\n"); if (type == 0) { fprintf(fp, "\t\t mov eax,[%s+ECX*4]\n",REG_DAT); fprintf(fp, "\t\t mov edi,[%s+EBX*4]\n",REG_DAT); fprintf(fp, "\t\t mov [%s+ECX*4],edi\n",REG_DAT); fprintf(fp, "\t\t mov [%s+EBX*4],eax\n",REG_DAT); } if (type == 1) { fprintf(fp, "\t\t mov eax,[%s+ECX*4]\n",REG_ADD); fprintf(fp, "\t\t mov edi,[%s+EBX*4]\n",REG_ADD); fprintf(fp, "\t\t mov [%s+ECX*4],edi\n",REG_ADD); fprintf(fp, "\t\t mov [%s+EBX*4],eax\n",REG_ADD); } if (type == 2) { fprintf(fp, "\t\t mov eax,[%s+ECX*4]\n",REG_DAT); fprintf(fp, "\t\t mov edi,[%s+EBX*4]\n",REG_ADD); fprintf(fp, "\t\t mov [%s+ECX*4],edi\n",REG_DAT); fprintf(fp, "\t\t mov [%s+EBX*4],eax\n",REG_ADD); } Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void ext(void) { int Opcode, BaseCode ; int type,regy ; for (type = 2 ; type < 8 ; type++) for (regy = 0 ; regy < 8 ; regy++) { if (type > 3 && type < 7) continue ; Opcode = 0x4800 | (type<<6) | regy ; BaseCode = Opcode & 0x48c0 ; if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 4 ; fprintf(fp, "\t\t and ecx, byte 7\n"); if (type == 2) /* byte to word */ { fprintf(fp, "\t\t movsx eax,byte [%s+ECX*4]\n",REG_DAT); fprintf(fp, "\t\t mov [%s+ECX*4],ax\n",REG_DAT); SetFlags('W',EAX,TRUE,FALSE,FALSE); } if (type == 3) /* word to long */ { fprintf(fp, "\t\t movsx eax,word [%s+ECX*4]\n",REG_DAT); fprintf(fp, "\t\t mov [%s+ECX*4],eax\n",REG_DAT); SetFlags('L',EAX,TRUE,FALSE,FALSE); } if (type == 7) /* byte to long */ { fprintf(fp, "\t\t movsx eax,byte [%s+ECX*4]\n",REG_DAT); fprintf(fp, "\t\t mov [%s+ECX*4],eax\n",REG_DAT); SetFlags('L',EAX,TRUE,FALSE,FALSE); } Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void swap(void) { int Opcode, BaseCode ; int sreg ; for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x4840 | sreg ; BaseCode = Opcode & 0x4840; if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 4 ; fprintf(fp, "\t\t and ecx, byte 7\n"); fprintf(fp, "\t\t mov eax, dword [%s+ECX*4]\n",REG_DAT); fprintf(fp, "\t\t ror eax, 16\n"); fprintf(fp, "\t\t test eax,eax\n"); fprintf(fp, "\t\t mov dword [%s+ECX*4],eax\n",REG_DAT); SetFlags('L',EAX,FALSE,FALSE,FALSE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } /* * Line A and Line F commands * */ void LineA(void) { int Count; /* Line A */ Align(); fprintf(fp, "%s:\n",GenerateLabel(0xA000,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); Exception(0x0A,0xA000); for (Count=0xA000;Count<0xB000;Count++) { OpcodeArray[Count] = 0xA000; } } void LineF(void) { int Count; /* Line F */ Align(); fprintf(fp, "%s:\n",GenerateLabel(0xF000,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); Exception(0x0B,0xF000); for (Count=0xF000;Count<0x10000;Count++) { OpcodeArray[Count] = 0xF000; } } /* * Moves To/From CCR and SR * * (Move from CCR is 68010 command) * */ void movesr(void) { int Opcode, BaseCode ; int type, mode, sreg ; int Dest ; char allow[] = "0-2345678-------" ; char Size; for (type = 0 ; type < 4 ; type++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x40c0 | (type << 9) | ( mode << 3 ) | sreg ; /* To has extra modes */ if (type > 1) { allow[0x9] = '9'; allow[0xa] = 'a'; allow[0xb] = 'b' ; } if ((type == 0) | (type == 3)) Size = 'W'; /* SR */ else Size = 'B'; /* CCR */ BaseCode = Opcode & 0x46f8 ; if (mode == 7) BaseCode |= sreg ; Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[BaseCode] == -2) { char TrueLabel[16]; Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (type > 1) /* move to */ TimingCycles += 12 ; else { if (mode < 2) TimingCycles += 6 ; else TimingCycles += 8 ; } /* If Move to SR then must be in Supervisor Mode */ if (type == 3) { sprintf(TrueLabel,GenerateLabel(0,1)); fprintf(fp, "\t\t test byte [%s],20h \t\t\t; Supervisor Mode ?\n",REG_SRH); fprintf(fp, "\t\t je near %s\n\n",TrueLabel); } /* 68010 Command ? */ if (type==1) CheckCPUtype(1); if (mode < 7) { fprintf(fp, "\t\t and ecx,byte 7\n"); } /* Always read/write word 2 bytes */ if (type < 2) { ReadCCR(Size,EBX); EffectiveAddressWrite(Dest & 15,'W',ECX,TRUE,"---DS-B",TRUE); } else { EffectiveAddressRead(Dest & 15,'W',ECX,EAX,"----S-B",FALSE); WriteCCR(Size); } Completed(); /* Exception if not Supervisor Mode */ if (type == 3) { /* Was in User Mode - Exception */ fprintf(fp, "%s:\n",TrueLabel); Exception(8,BaseCode); } } OpcodeArray[Opcode] = BaseCode ; } } } /* * Decimal mode Add / Subtracts * */ void abcd_sbcd(void) { int Opcode, BaseCode ; int regx,type,rm,regy,mode ; int ModeModX; int ModeModY; char *Label; for (type = 0 ; type < 2 ; type ++) /* 0=sbcd, 1=abcd */ for (regx = 0 ; regx < 8 ; regx++) for (rm = 0 ; rm < 2 ; rm++) for (regy = 0 ; regy < 8 ; regy++) { Opcode = 0x8100 | (type<<14) | (regx<<9) | (rm<<3) | regy ; BaseCode = Opcode & 0xc108 ; ModeModX = 0; ModeModY = 0; if (rm == 0) mode = 0 ; else { mode = 4 ; #ifdef A7ROUTINE if (regx == 7) { BaseCode |= (regx << 9); ModeModY = 16; } if (regy == 7) { BaseCode |= regy; ModeModX = 16; } #endif } if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if (mode == 4) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); AddEACycles = 0 ; if (rm == 0) TimingCycles += 6 ; else TimingCycles += 18 ; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx, byte 7\n"); fprintf(fp, "\t\t shr ecx, byte 9\n"); fprintf(fp, "\t\t and ecx, byte 7\n"); EffectiveAddressRead(mode+ModeModX,'B',EBX,EBX,"--C-S-B",TRUE); EffectiveAddressRead(mode+ModeModY,'B',ECX,EAX,"-BC-SDB",TRUE); CopyX(); if (type == 0) { fprintf(fp, "\t\t sbb al,bl\n"); fprintf(fp, "\t\t das\n"); } else { fprintf(fp, "\t\t adc al,bl\n"); fprintf(fp, "\t\t daa\n"); } /* Should only clear Zero flag if not zero */ Label = GenerateLabel(0,1); fprintf(fp, "\t\t mov ebx,edx\n"); fprintf(fp, "\t\t setc dl\n"); fprintf(fp, "\t\t jnz short %s\n\n",Label); /* Keep original Zero flag */ fprintf(fp, "\t\t and bl,40h ; Mask out Old Z\n"); fprintf(fp, "\t\t or dl,bl ; Copy across\n\n"); fprintf(fp, "%s:\n",Label); fprintf(fp, "\t\t mov bl,dl\n"); /* copy carry into sign */ fprintf(fp, "\t\t and bl,1\n"); fprintf(fp, "\t\t shl bl,7\n"); fprintf(fp, "\t\t and dl,7Fh\n"); fprintf(fp, "\t\t or dl,bl\n"); fprintf(fp, "\t\t mov [%s],edx\n",REG_X); EffectiveAddressWrite(mode,'B',ECX,EAX,"---DS-B",TRUE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } /* * Rotate Left / Right * */ void rol_ror(void) { int Opcode, BaseCode ; int dreg, dr, leng, ir, sreg ; char Size=' '; char * Label ; char * Regname="" ; char * RegnameECX ; for (dreg = 0 ; dreg < 8 ; dreg++) for (dr = 0 ; dr < 2 ; dr++) for (leng = 0 ; leng < 3 ; leng++) for (ir = 0 ; ir < 2 ; ir++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xe018 | (dreg<<9) | (dr<<8) | (leng<<6) | (ir<<5) | sreg ; BaseCode = Opcode & 0xe1f8 ; switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameECX = regnamesshort[ECX]; break; case 1: Size = 'W'; Regname = regnamesword[0]; RegnameECX = regnamesword[ECX]; break; case 2: Size = 'L'; Regname = regnameslong[0]; RegnameECX = regnameslong[ECX]; break; } if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (Size != 'L') TimingCycles += 6 ; else TimingCycles += 8 ; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); fprintf(fp, "\t\t shr ecx,byte 9\n"); if (ir == 0) { Immediate8(); } else { fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(0,'L',ECX,ECX,"-B--S-B",FALSE); fprintf(fp, "\t\t and ecx,byte 63\n"); } EffectiveAddressRead(0,Size,EBX,EAX,"-BC-S-B",FALSE); /* shift 0 - no time, no shift and clear carry */ Label = GenerateLabel(0,1); fprintf(fp, "\t\t jecxz %s\n",Label); /* allow 2 cycles per shift */ fprintf(fp, "\t\t mov edx,ecx\n"); fprintf(fp, "\t\t add edx,edx\n"); fprintf(fp, "\t\t sub dword [%s],edx\n",ICOUNT); if (dr == 0) fprintf(fp, "\t\t ror %s,cl\n",Regname); else fprintf(fp, "\t\t rol %s,cl\n",Regname); fprintf(fp, "\t\t setc ch\n"); fprintf(fp, "%s:\n",Label); SetFlags(Size,EAX,TRUE,FALSE,FALSE); /* fprintf(fp, "\t\t and dl,254\n"); Test clears Carry */ fprintf(fp, "\t\t or dl,ch\n"); EffectiveAddressWrite(0,Size,EBX,EAX,"--C-S-B",TRUE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void rol_ror_ea(void) { int Opcode, BaseCode ; int dr, mode, sreg ; int Dest ; char allow[] = "--2345678-------" ; for (dr = 0 ; dr < 2 ; dr++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xe6c0 | (dr<<8) | (mode<<3) | sreg ; BaseCode = Opcode & 0xfff8 ; if (mode == 7) BaseCode |= sreg ; Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 8 ; fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(Dest&0xf,'W',ECX,EAX,"--C-SDB",FALSE); if (dr == 0) fprintf(fp, "\t\t ror ax,1\n"); else fprintf(fp, "\t\t rol ax,1\n"); fprintf(fp, "\t\t setc bl\n"); SetFlags('W',EAX,TRUE,FALSE,FALSE); /* fprintf(fp, "\t\t and dl,254\n"); Test clears Carry */ fprintf(fp, "\t\t or dl,bl\n"); EffectiveAddressWrite(Dest&0xf,'W',ECX,EAX,"---DS-B",TRUE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * Logical Shift Left / Right * */ void lsl_lsr(void) { int Opcode, BaseCode ; int dreg, dr, leng, ir, sreg ; char Size=' '; char * Regname="" ; char * RegnameECX="" ; char * RegnameEDX="" ; char * Label ; for (dreg = 0 ; dreg < 8 ; dreg++) for (dr = 0 ; dr < 2 ; dr++) for (leng = 0 ; leng < 3 ; leng++) for (ir = 0 ; ir < 2 ; ir++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xe008 | (dreg<<9) | (dr<<8) | (leng<<6) | (ir<<5) | sreg ; BaseCode = Opcode & 0xe1f8 ; switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameECX = regnamesshort[ECX]; RegnameEDX = regnamesshort[EDX]; break; case 1: Size = 'W'; Regname = regnamesword[0]; RegnameECX = regnamesword[ECX]; RegnameEDX = regnamesword[EDX]; break; case 2: Size = 'L'; Regname = regnameslong[0]; RegnameECX = regnameslong[ECX]; RegnameEDX = regnameslong[EDX]; break; } if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (Size != 'L') TimingCycles += 6 ; else TimingCycles += 8 ; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); fprintf(fp, "\t\t shr ecx,byte 9\n"); if (ir == 0) { Immediate8(); } else { fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(0,'L',ECX,ECX,"-B--S-B",FALSE); fprintf(fp, "\t\t and ecx,byte 63\n"); } /* and 2 cycles per shift */ fprintf(fp, "\t\t mov edx,ecx\n"); fprintf(fp, "\t\t add edx,edx\n"); fprintf(fp, "\t\t sub dword [%s],edx\n",ICOUNT); EffectiveAddressRead(0,Size,EBX,EAX,"-BC-S-B",FALSE); /* ASG: on the 68k, the shift count is mod 64; on the x86, the */ /* shift count is mod 32; we need to check for shifts of 32-63 */ /* and produce zero */ Label = GenerateLabel(0,1); fprintf(fp, "\t\t test cl,0x20\n"); fprintf(fp, "\t\t jnz %s_BigShift\n",Label); fprintf(fp, "%s_Continue:\n",Label); if (dr == 0) fprintf(fp, "\t\t shr %s,cl\n",Regname); else fprintf(fp, "\t\t shl %s,cl\n",Regname); SetFlags(Size,EAX,FALSE,FALSE,FALSE); /* Clear Overflow flag */ fprintf(fp, "\t\t xor dh,dh\n"); EffectiveAddressWrite(0,Size,EBX,EAX,"--CDS-B",TRUE); /* if shift count is zero clear carry */ fprintf(fp, "\t\t jecxz %s\n",Label); fprintf(fp, "\t\t mov [%s],edx\n",REG_X); Completed(); Align(); fprintf(fp, "%s:\n",Label); SetFlags(Size,EAX,TRUE,FALSE,FALSE); Completed(); fprintf(fp, "%s_BigShift:\n",Label); if (dr == 0) { fprintf(fp, "\t\t shr %s,16\n",Regname); fprintf(fp, "\t\t shr %s,16\n",Regname); } else { fprintf(fp, "\t\t shl %s,16\n",Regname); fprintf(fp, "\t\t shl %s,16\n",Regname); } fprintf(fp, "\t\t jmp %s_Continue\n",Label); } OpcodeArray[Opcode] = BaseCode ; } } void lsl_lsr_ea(void) { int Opcode, BaseCode ; int dr, mode, sreg ; int Dest ; char allow[] = "--2345678-------" ; for (dr = 0 ; dr < 2 ; dr++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xe2c0 | (dr<<8) | (mode<<3) | sreg ; BaseCode = Opcode & 0xfff8 ; if (mode == 7) BaseCode |= sreg ; Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 8 ; fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(Dest&0xf,'W',ECX,EAX,"--C-SDB",FALSE); if (dr == 0) fprintf(fp, "\t\t shr ax,1\n"); else fprintf(fp, "\t\t shl ax,1\n"); SetFlags('W',EAX,FALSE,TRUE,FALSE); /* Clear Overflow flag */ fprintf(fp, "\t\t xor dh,dh\n"); EffectiveAddressWrite(Dest&0xf,'W',ECX,EAX,"---DS-B",TRUE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * Rotate Left / Right though Extend * */ void roxl_roxr(void) { int Opcode, BaseCode ; int dreg, dr, leng, ir, sreg ; char Size=' ' ; char * Regname="" ; char * RegnameECX="" ; char * Label ; for (dreg = 0 ; dreg < 8 ; dreg++) for (dr = 0 ; dr < 2 ; dr++) for (leng = 0 ; leng < 3 ; leng++) for (ir = 0 ; ir < 2 ; ir++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xe010 | (dreg<<9) | (dr<<8) | (leng<<6) | (ir<<5) | sreg ; BaseCode = Opcode & 0xe1f8 ; switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameECX = regnamesshort[ECX]; break; case 1: Size = 'W'; Regname = regnamesword[0]; RegnameECX = regnamesword[ECX]; break; case 2: Size = 'L'; Regname = regnameslong[0]; RegnameECX = regnameslong[ECX]; break; } if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); if (Size != 'L') TimingCycles += 6 ; else TimingCycles += 8 ; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); fprintf(fp, "\t\t shr ecx,byte 9\n"); if (ir == 0) { Immediate8(); } else { fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(0,'L',ECX,ECX,"-B--S-B",FALSE); fprintf(fp, "\t\t and ecx,byte 63\n"); } /* allow 2 cycles per shift */ fprintf(fp, "\t\t mov edx,ecx\n"); fprintf(fp, "\t\t add edx,edx\n"); fprintf(fp, "\t\t sub dword [%s],edx\n",ICOUNT); EffectiveAddressRead(0,Size,EBX,EAX,"-BC-SDB",FALSE); /* move X into C so RCR & RCL can be used */ /* RCR & RCL only set the carry flag */ CopyX(); if (dr == 0) fprintf(fp, "\t\t rcr %s,cl\n",Regname); else fprintf(fp, "\t\t rcl %s,cl\n",Regname); fprintf(fp, "\t\t setc ch\n"); SetFlags(Size,EAX,TRUE,FALSE,FALSE); /* fprintf(fp, "\t\t and dl,254\n"); Test Clears Carry */ EffectiveAddressWrite(0,Size,EBX,EAX,"--CDS-B",TRUE); /* if shift count is zero clear carry */ Label = GenerateLabel(0,1); fprintf(fp, "\t\t test cl,cl\n"); fprintf(fp, "\t\t jz %s\n",Label); /* Add in Carry Flag */ fprintf(fp, "\t\t or dl,ch\n"); fprintf(fp, "\t\t mov [%s],dl\n",REG_X); Completed(); /* copy X onto C when shift is zero */ Align(); fprintf(fp, "%s:\n",Label); fprintf(fp, "\t\t mov ecx,[%s]\n",REG_X); fprintf(fp, "\t\t and ecx,byte 1\n"); fprintf(fp, "\t\t or edx,ecx\n"); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void roxl_roxr_ea(void) { int Opcode, BaseCode ; int dr, mode, sreg ; int Dest ; char allow[] = "--2345678-------" ; for (dr = 0 ; dr < 2 ; dr++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xe4c0 | (dr<<8) | (mode<<3) | sreg ; BaseCode = Opcode & 0xfff8 ; if (mode == 7) BaseCode |= sreg ; Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 8 ; fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(Dest&0xf,'W',ECX,EAX,"--C-SDB",FALSE); /* move X into C so RCR & RCL can be used */ /* RCR & RCL only set the carry flag */ CopyX(); if (dr == 0) fprintf(fp, "\t\t rcr ax,1\n"); else fprintf(fp, "\t\t rcl ax,1\n"); fprintf(fp, "\t\t setc bl\n"); SetFlags('W',EAX,TRUE,FALSE,FALSE); /* fprintf(fp, "\t\t and dl,254\n"); - Intel Clears on Test */ fprintf(fp, "\t\t or dl,bl\n"); EffectiveAddressWrite(Dest&0xf,'W',ECX,EAX,"---DS-B",TRUE); fprintf(fp, "\t\t mov [%s],edx\n",REG_X); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * Arithmetic Shift Left / Right * */ void asl_asr(void) { int Opcode, BaseCode ; int dreg, dr, leng, ir, sreg ; char Size=' '; char * Sizename="" ; char * Regname="" ; char * RegnameEDX="" ; char * RegnameECX="" ; char * Label; /* Normal routines for codes */ for (dreg = 0 ; dreg < 8 ; dreg++) for (dr = 0 ; dr < 2 ; dr++) for (leng = 0 ; leng < 3 ; leng++) for (ir = 0 ; ir < 2 ; ir++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xe000 | (dreg<<9) | (dr<<8) | (leng<<6) | (ir<<5) | sreg ; BaseCode = Opcode & 0xe1f8 ; switch (leng) { case 0: Size = 'B'; Regname = regnamesshort[0]; RegnameECX = regnamesshort[ECX]; RegnameEDX = regnamesshort[EDX]; break; case 1: Size = 'W'; Regname = regnamesword[0]; RegnameECX = regnamesword[ECX]; RegnameEDX = regnamesword[EDX]; break; case 2: Size = 'L'; Regname = regnameslong[0]; RegnameECX = regnameslong[ECX]; RegnameEDX = regnameslong[EDX]; break; } if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); Label = GenerateLabel(0,1); if (Size != 'L') TimingCycles += 6 ; else TimingCycles += 8 ; fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); fprintf(fp, "\t\t shr ecx,byte 9\n"); EffectiveAddressRead(0,Size,EBX,EAX,"-BC-S-B",FALSE); if (ir == 0) { Immediate8(); } else { fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(0,'L',ECX,ECX,"-B--S-B",FALSE); fprintf(fp, "\t\t and ecx,byte 63\n"); fprintf(fp, "\t\t jz short %s\n",Label); } /* allow 2 cycles per shift */ fprintf(fp, "\t\t mov edx,ecx\n"); fprintf(fp, "\t\t add edx,edx\n"); fprintf(fp, "\t\t sub dword [%s],edx\n",ICOUNT); if (dr == 0) { /* ASR */ /* ASG: on the 68k, the shift count is mod 64; on the x86, the */ /* shift count is mod 32; we need to check for shifts of 32-63 */ /* and effectively shift 31 */ fprintf(fp, "\t\t shrd edx,ecx,6\n"); fprintf(fp, "\t\t sar edx,31\n"); fprintf(fp, "\t\t and edx,31\n"); fprintf(fp, "\t\t or ecx,edx\n"); fprintf(fp, "\t\t sar %s,cl\n",Regname); /* Mode 0 write does not affect Flags */ EffectiveAddressWrite(0,Size,EBX,EAX,"---DS-B",TRUE); /* Update Flags */ fprintf(fp, "\t\t lahf\n"); #ifdef STALLCHECK ClearRegister(EDX); fprintf(fp, "\t\t mov dl,ah\n"); #else fprintf(fp, "\t\t movzx edx,ah\n"); #endif fprintf(fp, "\t\t mov [%s],edx\n",REG_X); } else { /* ASL */ /* Check to see if Overflow should be set */ fprintf(fp,"\t\t mov edi,eax\t\t; Save It\n"); ClearRegister(EDX); fprintf(fp,"\t\t stc\n"); fprintf(fp,"\t\t rcr %s,1\t\t; d=1xxxx\n",RegnameEDX); fprintf(fp,"\t\t sar %s,cl\t\t; d=1CCxx\n",RegnameEDX); fprintf(fp,"\t\t and eax,edx\n"); fprintf(fp,"\t\t jz short %s_V\t\t; No Overflow\n",Label); fprintf(fp,"\t\t cmp eax,edx\n"); fprintf(fp,"\t\t je short %s_V\t\t; No Overflow\n",Label); /* Set Overflow */ fprintf(fp,"\t\t mov edx,0x800\n"); fprintf(fp,"\t\t jmp short %s_OV\n",Label); fprintf(fp,"%s_V:\n",Label); ClearRegister(EDX); fprintf(fp,"%s_OV:\n",Label); /* more than 31 shifts and long */ if ((ir==1) && (leng==2)) { fprintf(fp,"\t\t test cl,0x20\n"); fprintf(fp,"\t\t jnz short %s_32\n\n",Label); } fprintf(fp,"\t\t mov eax,edi\t\t; Restore It\n"); fprintf(fp, "\t\t sal %s,cl\n",Regname); EffectiveAddressWrite(0,Size,EBX,EAX,"---DS-B",TRUE); fprintf(fp, "\t\t lahf\n"); fprintf(fp, "\t\t mov dl,ah\n"); fprintf(fp, "\t\t mov [%s],edx\n",REG_X); } Completed(); if (ir != 0) { Align(); fprintf(fp, "%s:\n",Label); if (dr == 0) { /* ASR - Test clears V and C */ SetFlags(Size,EAX,TRUE,FALSE,FALSE); } else { /* ASL - Keep existing Carry flag, Clear V */ fprintf(fp, "\t\t mov ebx,edx\n"); fprintf(fp, "\t\t and ebx,byte 1\n"); SetFlags(Size,EAX,TRUE,FALSE,FALSE); fprintf(fp, "\t\t or edx,ebx\n"); if (leng==2) { Completed(); /* > 31 Shifts */ fprintf(fp, "%s_32:\n",Label); fprintf(fp, "\t\t mov dl,40h\n"); // Zero flag ClearRegister(EAX); EffectiveAddressWrite(0,Size,EBX,EAX,"----S-B",TRUE); } } Completed(); } } OpcodeArray[Opcode] = BaseCode ; } /* End with special routines for ASL.x #1,Dx */ /* To do correct V setting, ASL needs quite a */ /* bit of additional code. A Shift of one has */ /* correct flags on Intel, and is very common */ /* in 68000 programs. */ for (leng = 0 ; leng < 3 ; leng++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xe300 | (leng<<6) | sreg ; BaseCode = Opcode & 0xe3c8 ; switch (leng) { case 0: Sizename = "byte"; break; case 1: Sizename = "word"; break; case 2: Sizename = "long"; break; } if (sreg == 0) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); fprintf(fp, "\t\t add esi,byte 2\n\n"); Label = GenerateLabel(0,1); if (Size != 'L') TimingCycles += 6 ; else TimingCycles += 8 ; fprintf(fp, "\t\t and ecx,byte 7\n"); fprintf(fp, "\t\t sal %s [%s+ecx*4],1\n",Sizename,REG_DAT); SetFlags('L',EAX,FALSE,TRUE,FALSE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } void asl_asr_ea(void) { int Opcode, BaseCode ; int dr, mode, sreg ; int Dest ; char allow[] = "--2345678-------" ; for (dr = 0 ; dr < 2 ; dr++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0xe0c0 | (dr<<8) | (mode<<3) | sreg ; BaseCode = Opcode & 0xfff8 ; if (mode == 7) BaseCode |= sreg ; Dest = EAtoAMN(BaseCode, FALSE); if (allow[Dest&0xf] != '-') { if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); TimingCycles += 8 ; fprintf(fp, "\t\t and ecx,byte 7\n"); EffectiveAddressRead(Dest&0xf,'W',ECX,EAX,"--C-SDB",FALSE); if (dr == 0) fprintf(fp, "\t\t sar ax,1\n"); else fprintf(fp, "\t\t sal ax,1\n"); SetFlags('W',EAX,FALSE,TRUE,TRUE); EffectiveAddressWrite(Dest&0xf,'W',ECX,EAX,"----S-B",FALSE); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * Divide Commands */ void divides(void) { int dreg, type, mode, sreg ; int Opcode, BaseCode ; int Dest ; char allow[] = "0-23456789ab-----" ; char TrapLabel[16]; int Cycles; int divide_cycles[12] = { 38,0,42,42,44,46,50,46,50,46,48,42 }; for (dreg = 0 ; dreg < 8 ; dreg++) for (type = 0 ; type < 2 ; type++) for (mode = 0 ; mode < 8 ; mode++) for (sreg = 0 ; sreg < 8 ; sreg++) { Opcode = 0x80c0 | (dreg<<9) | (type<<8) | (mode<<3) | sreg ; BaseCode = Opcode & 0x81f8 ; if (mode == 7) { BaseCode |= sreg ; } Dest = EAtoAMN(Opcode, FALSE); if (allow[Dest&0x0f] != '-') { if (OpcodeArray[ BaseCode ] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); if ((Dest >= 2) && (Dest <=10)) SavePreviousPC(); fprintf(fp, "\t\t add esi,byte 2\n\n"); /* Save EDX (in case of overflow) */ fprintf(fp, "\t\t and edx,byte -2\n"); fprintf(fp, "\t\t mov [%s],edx\n",REG_CCR); /* Cycle Timing (if succeeds OK) */ Cycles = divide_cycles[Dest & 0x0f] + 95 + (type * 17); if (Cycles > 127) fprintf(fp, "\t\t sub dword [%s],%d\n",ICOUNT,Cycles); else fprintf(fp, "\t\t sub dword [%s],byte %d\n",ICOUNT,Cycles); if (mode < 7) { fprintf(fp, "\t\t mov ebx,ecx\n"); fprintf(fp, "\t\t and ebx,byte 7\n"); } fprintf(fp, "\t\t shr ecx, byte 9\n"); fprintf(fp, "\t\t and ecx, byte 7\n"); sprintf(TrapLabel, "%s", GenerateLabel(0,1) ) ; EffectiveAddressRead(Dest,'W',EBX,EAX,"A-C-SDB",FALSE); /* source */ fprintf(fp, "\t\t test ax,ax\n"); fprintf(fp, "\t\t je near %s_ZERO\t\t;do div by zero trap\n", TrapLabel); if (type == 1) /* signed */ { fprintf(fp, "\t\t movsx ebx,ax\n"); } else { fprintf(fp, "\t\t movzx ebx,ax\n"); } EffectiveAddressRead(0,'L',ECX,EAX,"ABC-SDB",FALSE); /* dest */ if (type == 1) /* signed */ { fprintf(fp, "\t\t cdq\n"); /* EDX:EAX = 64 bit signed */ fprintf(fp, "\t\t idiv ebx\n"); /* EBX = 32 bit */ /* Check for Overflow */ fprintf(fp, "\t\t movsx ebx,ax\n"); fprintf(fp, "\t\t cmp eax,ebx\n"); fprintf(fp, "\t\t jne short %s_OVER\n",TrapLabel); } else { ClearRegister(EDX); fprintf(fp, "\t\t div ebx\n"); /* Check for Overflow */ fprintf(fp, "\t\t test eax, 0FFFF0000H\n"); fprintf(fp, "\t\t jnz short %s_OVER\n",TrapLabel); } /* Sort out Result */ fprintf(fp, "\t\t shl edx, byte 16\n"); fprintf(fp, "\t\t mov dx,ax\n"); fprintf(fp, "\t\t mov [%s+ECX*4],edx\n",REG_DAT); SetFlags('W',EDX,TRUE,FALSE,FALSE); Completed(); /* Overflow */ Align(); fprintf(fp, "%s_OVER:\n",TrapLabel); fprintf(fp, "\t\t mov edx,[%s]\n",REG_CCR); fprintf(fp, "\t\t or edx,0x0800\t\t;V flag\n"); Completed(); /* Division by Zero */ Align(); fprintf(fp, "%s_ZERO:\t\t ;Do divide by zero trap\n", TrapLabel); /* Correct cycle counter for error */ fprintf(fp, "\t\t add dword [%s],byte %d\n",ICOUNT,95 + (type * 17)); fprintf(fp, "\t\t mov al,5\n"); Exception(-1,BaseCode); Completed(); } OpcodeArray[Opcode] = BaseCode ; } } } /* * 68010 Extra Opcodes * * move from CCR is done above * */ void ReturnandDeallocate(void) { int BaseCode = 0x4e74 ; if (OpcodeArray[BaseCode] == -2) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode,0)); CheckCPUtype(1); SavePreviousPC(); TimingCycles += 16; OpcodeArray[BaseCode] = BaseCode ; /* Get Return Address */ fprintf(fp, "\t\t mov eax,[%s]\n",REG_A7); Memory_Read('L',EAX,"---D--B",1); /* Get Displacement */ Memory_Fetch('W',EBX,TRUE); /* Set PC = New Address */ fprintf(fp, "\t\t mov esi,eax\n"); /* Correct Stack for Return Address and Displacement */ fprintf(fp, "\t\t add ebx,byte 4\n"); fprintf(fp, "\t\t add dword [%s],ebx\n",REG_A7); MemoryBanking(BaseCode); Completed(); } } void MoveControlRegister(void) { int Direction; int BaseCode = 0x4e7a ; for (Direction=0;Direction<2;Direction++) { Align(); fprintf(fp, "%s:\n",GenerateLabel(BaseCode+Direction,0)); TimingCycles += 4; /* Assume same as move usp */ CheckCPUtype(1); fprintf(fp, "\t\t test byte [%s],20h \t\t\t; Supervisor Mode ?\n",REG_SRH); fprintf(fp, "\t\t jz short OP%d_%4.4x_Trap\n",CPU,BaseCode+Direction); fprintf(fp, "\t\t add esi,byte 2\n"); if (CPU==2) fprintf(fp, "\t\t xor esi,2\n"); /* ASG */ #ifdef STALLCHECK ClearRegister(EBX); fprintf(fp, "\t\t mov bx,[esi+ebp]\n"); #else fprintf(fp, "\t\t movzx ebx,word [esi+ebp]\n"); #endif if (CPU==2) fprintf(fp, "\t\t xor esi,2\n"); /* ASG */ fprintf(fp, "\t\t add esi,byte 2\n"); fprintf(fp, "\t\t mov eax,ebx\n"); fprintf(fp, "\t\t mov ecx,ebx\n"); /* Sort out Register */ fprintf(fp, "\t\t shr ebx,12\n"); /* Sort out Control Register ID */ fprintf(fp, "\t\t and eax,byte 1\n"); fprintf(fp, "\t\t shr ecx,10\n"); fprintf(fp, "\t\t and ecx,2\n"); fprintf(fp, "\t\t or ecx,eax\n"); if (Direction==0) { /* from Control */ fprintf(fp, "\t\t mov eax,[%s+ecx*4]\n",REG_SFC); fprintf(fp, "\t\t mov %s,eax\n",REG_DAT_EBX); } else { /* To Control */ fprintf(fp, "\t\t mov eax,%s\n",REG_DAT_EBX); /* Mask out for SFC & DFC */ fprintf(fp, "\t\t test cl,2\n"); fprintf(fp, "\t\t jne short OP%d_%4.4x_Mask\n",CPU,BaseCode+Direction); fprintf(fp, "\t\t and eax,byte 7\n"); fprintf(fp, "OP%d_%4.4x_Mask:\n",CPU,BaseCode+Direction); /* Write to control */ fprintf(fp, "\t\t mov [%s+ecx*4],eax\n",REG_SFC); } Completed(); /* Not Supervisor Mode */ Align(); fprintf(fp, "OP%d_%4.4x_Trap:\n",CPU,BaseCode+Direction); Exception(8,BaseCode+Direction); OpcodeArray[BaseCode+Direction] = BaseCode+Direction; } } void MoveAddressSpace(void) { } /* * Generate Jump Table * */ void JumpTable(void) { int Opcode,l,op; fprintf(fp, "DD OP%d_1000\n",CPU); l = 0 ; for (Opcode=0x0;Opcode<0x10000;) { op = OpcodeArray[Opcode]; fprintf(fp, "DD "); l = 1 ; while (op == OpcodeArray[Opcode+l] && ((Opcode+l) & 0xfff) != 0) { l++ ; } Opcode += l ; if (l > 255) { if (op > -1) fprintf(fp, "OP%d_%4.4x - OP%d_1000\n",CPU,op,CPU); else fprintf(fp, "ILLEGAL - OP%d_1000\n",CPU); fprintf(fp, "DW %d\n", l); } else { if (op > -1) fprintf(fp, "(OP%d_%4.4x - OP%d_1000) + (%d * 1000000h)\n",CPU,op,CPU,l); else fprintf(fp, "(ILLEGAL - OP%d_1000) + (%d * 1000000h)\n",CPU,l); } } } void CodeSegmentBegin(void) { /* Messages */ fprintf(fp, "; Make68K - V%s - Copyright 1998, Mike Coates ([email protected])\n", VERSION); fprintf(fp, "; & Darren Olafson ([email protected])\n\n"); /* Needed code to make it work! */ fprintf(fp, "\t\t BITS 32\n\n"); fprintf(fp, "\t\t GLOBAL %s_RUN\n",CPUtype); fprintf(fp, "\t\t GLOBAL %s_RESET\n",CPUtype); fprintf(fp, "\t\t GLOBAL %s_regs\n",CPUtype); fprintf(fp, "\t\t GLOBAL %s_COMPTABLE\n",CPUtype); fprintf(fp, "\t\t GLOBAL %s_OPCODETABLE\n",CPUtype); /* ASG - only one interface to memory now */ fprintf(fp, "\t\t EXTERN %sm68k_ICount\n", PREF); fprintf(fp, "\t\t EXTERN %sa68k_memory_intf\n", PREF); fprintf(fp, "\t\t EXTERN %smem_amask\n", PREF); fprintf(fp, "; Vars Mame declares / needs access to\n\n"); fprintf(fp, "\t\t EXTERN %smame_debug\n", PREF); fprintf(fp, "\t\t EXTERN %sillegal_op\n", PREF); fprintf(fp, "\t\t EXTERN %sillegal_pc\n", PREF); fprintf(fp, "\t\t EXTERN %sOP_ROM\n", PREF); fprintf(fp, "\t\t EXTERN %sOP_RAM\n", PREF); fprintf(fp, "\t\t EXTERN %sopcode_entry\n", PREF); // fprintf(fp, "\t\t EXTERN %scur_mrhard\n", PREF); #ifdef MAME_DEBUG fprintf(fp, "\t\t EXTERN %sm68k_illegal_opcode\n", PREF); #endif #ifdef OS2 fprintf(fp, "\t\t SECTION maincode USE32 FLAT CLASS=CODE\n\n"); #else fprintf(fp, "\t\t SECTION .text\n\n"); #endif /* Reset routine */ fprintf(fp, "%s_RESET:\n",CPUtype); fprintf(fp, "\t\t pushad\n\n"); fprintf(fp, "; Build Jump Table (not optimised!)\n\n"); fprintf(fp, "\t\t lea edi,[%s_OPCODETABLE]\t\t; Jump Table\n", CPUtype); fprintf(fp, "\t\t lea esi,[%s_COMPTABLE]\t\t; RLE Compressed Table\n", CPUtype); /* Reference Point in EBP */ fprintf(fp, "\t\t mov ebp,[esi]\n"); fprintf(fp, "\t\t add esi,byte 4\n"); fprintf(fp, "RESET0:\n"); fprintf(fp, "\t\t mov eax,[esi]\n"); fprintf(fp, "\t\t mov ecx,eax\n"); fprintf(fp, "\t\t and eax,0xffffff\n"); fprintf(fp, "\t\t add eax,ebp\n"); fprintf(fp, "\t\t add esi,byte 4\n"); /* if count is zero, then it's a word RLE length */ fprintf(fp, "\t\t shr ecx,24\n"); fprintf(fp, "\t\t jne short RESET1\n"); #ifdef STALLCHECK ClearRegister(ECX); fprintf(fp, "\t\t mov cx,[esi]\t\t; Repeats\n"); #else fprintf(fp, "\t\t movzx ecx,word [esi]\t\t; Repeats\n"); #endif fprintf(fp, "\t\t add esi,byte 2\n"); fprintf(fp, "\t\t jecxz RESET2\t\t; Finished!\n"); fprintf(fp, "RESET1:\n"); fprintf(fp, "\t\t mov [edi],eax\n"); fprintf(fp, "\t\t add edi,byte 4\n"); fprintf(fp, "\t\t dec ecx\n"); fprintf(fp, "\t\t jnz short RESET1\n"); fprintf(fp, "\t\t jmp short RESET0\n"); fprintf(fp, "RESET2:\n"); fprintf(fp, "\t\t popad\n"); fprintf(fp, "\t\t ret\n\n"); /* Emulation Entry Point */ Align(); fprintf(fp, "%s_RUN:\n",CPUtype); fprintf(fp, "\t\t pushad\n"); fprintf(fp, "\t\t mov esi,[%s]\n",REG_PC); fprintf(fp, "\t\t mov edx,[%s]\n",REG_CCR); fprintf(fp, "\t\t mov ebp,dword [%sOP_ROM]\n", PREF); fprintf(fp,"; Check for Interrupt waiting\n\n"); fprintf(fp,"\t\t test [%s],byte 07H\n",REG_IRQ); fprintf(fp,"\t\t jne near interrupt\n\n"); fprintf(fp, "IntCont:\n"); /* See if was only called to check for Interrupt */ fprintf(fp, "\t\t test dword [%s],-1\n",ICOUNT); fprintf(fp, "\t\t js short MainExit\n\n"); #ifdef FBA_DEBUG fprintf(fp, "\n\t\t test byte [%smame_debug],byte 0xff\n", PREF); fprintf(fp, "\t\t jns near .NoDebug\n"); fprintf(fp, "\t\t call near FBADebugActive\n\n"); fprintf(fp, ".NoDebug\n"); #endif if(CPU==2) { /* 32 Bit */ fprintf(fp, "\t\t mov eax,2\n"); /* ASG */ fprintf(fp, "\t\t xor eax,esi\n"); /* ASG */ #ifdef STALLCHECK ClearRegister(ECX); fprintf(fp, "\t\t mov cx,[eax+ebp]\n"); #else fprintf(fp, "\t\t movzx ecx,word [eax+ebp]\n"); #endif } else { /* 16 Bit Fetch */ #ifdef STALLCHECK ClearRegister(ECX); fprintf(fp, "\t\t mov cx,[esi+ebp]\n"); #else fprintf(fp, "\t\t movzx ecx,word [esi+ebp]\n"); #endif } fprintf(fp, "\t\t jmp [%s_OPCODETABLE+ecx*4]\n", CPUtype); Align(); fprintf(fp, "MainExit:\n"); fprintf(fp, "\t\t mov [%s],esi\t\t; Save PC\n",REG_PC); fprintf(fp, "\t\t mov [%s],edx\n",REG_CCR); fprintf(fp, "\t\t test byte [%s],20H\n",REG_SRH); fprintf(fp, "\t\t mov eax,[%s]\t\t; Get A7\n",REG_A7); fprintf(fp, "\t\t jne short ME1\t\t; Mode ?\n"); fprintf(fp, "\t\t mov [%s],eax\t\t;Save in USP\n",REG_USP); fprintf(fp, "\t\t jmp short MC68Kexit\n"); fprintf(fp, "ME1:\n"); fprintf(fp, "\t\t mov [%s],eax\n",REG_ISP); fprintf(fp, "MC68Kexit:\n"); /* If in Debug mode make normal SR register */ #ifdef MAME_DEBUG ReadCCR('W', ECX); fprintf(fp, "\t\t mov [%s],eax\n\n",REG_S); #endif fprintf(fp, "\t\t popad\n"); fprintf(fp, "\t\t ret\n"); /* Check for Pending Interrupts */ Align(); fprintf(fp, "; Interrupt check\n\n"); fprintf(fp, "interrupt:\n"); /* check to exclude interrupts */ fprintf(fp, "\t\t mov eax,[%s]\n",REG_IRQ); fprintf(fp, "\t\t and eax,byte 07H\n"); fprintf(fp, "\t\t cmp al,7\t\t ; Always take 7\n"); fprintf(fp, "\t\t je short procint\n\n"); fprintf(fp, "\t\t mov ebx,[%s]\t\t; int mask\n",REG_SRH); fprintf(fp, "\t\t and ebx,byte 07H\n"); fprintf(fp, "\t\t cmp eax,ebx\n"); fprintf(fp, "\t\t jle near IntCont\n\n"); /* Take pending Interrupt */ Align(); fprintf(fp, "procint:\n"); /* LVR - Enable proper IRQ handling (require explicit acknowledge) */ /* fprintf(fp, "\t\t and byte [%s],78h\t\t; remove interrupt & stop\n\n",REG_IRQ); */ fprintf(fp, "\t\t and byte [%s],7fh\t\t; remove stop\n\n",REG_IRQ); /* Get Interrupt Vector from callback */ fprintf(fp, "\t\t push eax\t\t; save level\n\n"); if (SavedRegs[EBX] == '-') { fprintf(fp, "\t\t push EBX\n"); } else { fprintf(fp, "\t\t mov ebx,eax\n"); } if (SavedRegs[ESI] == '-') { fprintf(fp, "\t\t mov [%s],ESI\n",REG_PC); } if (SavedRegs[EDX] == '-') { fprintf(fp, "\t\t mov [%s],edx\n",REG_CCR); } /* ----- Win32 uses FASTCALL (By Kenjo)----- */ #ifdef FASTCALL fprintf(fp, "\t\t mov %s, eax\t\t; irq line #\n",FASTCALL_FIRST_REG); fprintf(fp, "\t\t call dword [%s]\t; get the IRQ level\n", REG_IRQ_CALLBACK); #else fprintf(fp, "\t\t push eax\t\t; irq line #\n"); fprintf(fp, "\t\t call dword [%s]\t; get the IRQ level\n", REG_IRQ_CALLBACK); fprintf(fp, "\t\t lea esp,[esp+4]\n"); #endif if (SavedRegs[EDX] == '-') { fprintf(fp, "\t\t mov edx,[%s]\n",REG_CCR); } if (SavedRegs[ESI] == '-') { fprintf(fp, "\t\t mov esi,[%s]\n",REG_PC); } /* Do we want to use normal vector number ? */ fprintf(fp, "\t\t test eax,eax\n"); fprintf(fp, "\t\t jns short AUTOVECTOR\n"); /* Only need EBX restored if default vector to be used */ if (SavedRegs[EBX] == '-') { fprintf(fp, "\t\t pop EBX\n"); } /* Just get default vector */ fprintf(fp, "\t\t mov eax,ebx\n"); fprintf(fp, "\t\t add eax,byte 24\t\t; Vector\n\n"); fprintf(fp, "AUTOVECTOR:\n\n"); Exception(-1,0xFFFF); fprintf(fp, "\t\t pop eax\t\t; set Int mask\n"); fprintf(fp, "\t\t mov bl,byte [%s]\n",REG_SRH); fprintf(fp, "\t\t and bl,0F8h\n"); fprintf(fp, "\t\t or bl,al\n"); fprintf(fp, "\t\t mov byte [%s],bl\n\n",REG_SRH); fprintf(fp, "\t\t jmp IntCont\n\n"); /* Exception Routine */ Align(); fprintf(fp, "Exception:\n"); fprintf(fp, "\t\t push edx\t\t; Save flags\n"); fprintf(fp, "\t\t and eax,0FFH\t\t; Zero Extend IRQ Vector\n"); fprintf(fp, "\t\t push eax\t\t; Save for Later\n"); /* Update Cycle Count */ fprintf(fp, "\t\t mov al,[exception_cycles+eax]\t\t; Get Cycles\n"); fprintf(fp, "\t\t sub [%s],eax\t\t; Decrement ICount\n",ICOUNT); ReadCCR('W',ECX); fprintf(fp, "\t\t mov edi,[%s]\t\t; Get A7\n",REG_A7); fprintf(fp, "\t\t test ah,20H\t; Which Mode ?\n"); fprintf(fp, "\t\t jne short ExSuperMode\t\t; Supervisor\n"); fprintf(fp, "\t\t or byte [%s],20H\t; Set Supervisor Mode\n",REG_SRH); fprintf(fp, "\t\t mov [%s],edi\t\t; Save in USP\n",REG_USP); fprintf(fp, "\t\t mov edi,[%s]\t\t; Get ISP\n",REG_ISP); /* Write SR first (since it's in a register) */ fprintf(fp, "ExSuperMode:\n"); fprintf(fp, "\t\t sub edi,byte 6\n"); fprintf(fp, "\t\t mov [%s],edi\t\t; Put in A7\n",REG_A7); Memory_Write('W',EDI,EAX,"----S-B",2); /* Then write PC */ fprintf(fp, "\t\t add edi,byte 2\n"); Memory_Write('L',EDI,ESI,"------B",0); /* Get new PC */ fprintf(fp, "\t\t pop eax\t\t;Level\n"); fprintf(fp, "\t\t shl eax,2\n"); fprintf(fp, "\t\t add eax,[%s]\n",REG_VBR); /* 68010+ Vector Base */ /* Direct Read */ Memory_Read('L',EAX,"------B",0); fprintf(fp, "\t\t mov esi,eax\t\t;Set PC\n"); fprintf(fp, "\t\t pop edx\t\t; Restore flags\n"); /* Sort out any bank changes */ MemoryBanking(1); fprintf(fp, "\t\t ret\n"); #ifdef FBA_DEBUG fprintf(fp,"\n; Call FBA debugging callback\n\n"); fprintf(fp, "FBADebugActive:"); fprintf(fp, "\t\t mov [%s],ESI\n",REG_PC); fprintf(fp, "\t\t mov [%s],EDX\n",REG_CCR); fprintf(fp, "\t\t call [%sa68k_memory_intf+0]\n", PREF); if (SavedRegs[EDX] == '-') { fprintf(fp, "\t\t mov EDX,[%s]\n",REG_CCR); } if (SavedRegs[ESI] == '-') { fprintf(fp, "\t\t mov ESI,[%s]\n",REG_PC); } if (SavedRegs[EBP] == '-') { fprintf(fp, "\t\t mov ebp,dword [%sOP_ROM]\n", PREF); } fprintf(fp,"\n; Now continue as usual\n\n"); fprintf(fp, "\t\t ret\n"); #endif } void CodeSegmentEnd(void) { #ifdef OS2 fprintf(fp, "\t\t SECTION maindata USE32 FLAT CLASS=DATA\n\n"); #else fprintf(fp, "\t\t SECTION .data\n"); #endif fprintf(fp, "\n\t\t align 16\n"); fprintf(fp, "%s_ICount\n",CPUtype); fprintf(fp, "asm_count\t DD 0\n\n"); /* Memory structure for 68000 registers */ /* Same layout as structure in CPUDEFS.H */ fprintf(fp, "\n\n; Register Structure\n\n"); fprintf(fp, "%s_regs\n",CPUtype); fprintf(fp, "R_D0\t DD 0\t\t\t ; Data Registers\n"); fprintf(fp, "R_D1\t DD 0\n"); fprintf(fp, "R_D2\t DD 0\n"); fprintf(fp, "R_D3\t DD 0\n"); fprintf(fp, "R_D4\t DD 0\n"); fprintf(fp, "R_D5\t DD 0\n"); fprintf(fp, "R_D6\t DD 0\n"); fprintf(fp, "R_D7\t DD 0\n\n"); fprintf(fp, "R_A0\t DD 0\t\t\t ; Address Registers\n"); fprintf(fp, "R_A1\t DD 0\n"); fprintf(fp, "R_A2\t DD 0\n"); fprintf(fp, "R_A3\t DD 0\n"); fprintf(fp, "R_A4\t DD 0\n"); fprintf(fp, "R_A5\t DD 0\n"); fprintf(fp, "R_A6\t DD 0\n"); fprintf(fp, "R_A7\t DD 0\n\n"); fprintf(fp, "R_ISP\t DD 0\t\t\t ; Supervisor Stack\n"); fprintf(fp, "R_SR_H\t DD 0\t\t\t ; Status Register High TuSuuIII\n"); fprintf(fp, "R_CCR\t DD 0\t\t\t ; CCR Register in Intel Format\n"); fprintf(fp, "R_XC\t DD 0\t\t\t ; Extended Carry uuuuuuuX\n"); fprintf(fp, "R_PC\t DD 0\t\t\t ; Program Counter\n"); fprintf(fp, "R_IRQ\t DD 0\t\t\t ; IRQ Request Level\n\n"); fprintf(fp, "R_SR\t DD 0\t\t\t ; Motorola Format SR\n\n"); fprintf(fp, "R_IRQ_CALLBACK\t DD 0\t\t\t ; irq callback (get vector)\n\n"); fprintf(fp, "R_PPC\t DD 0\t\t\t ; Previous Program Counter\n"); fprintf(fp, "R_RESET_CALLBACK\t DD 0\t\t\t ; Reset Callback\n"); fprintf(fp, "R_SFC\t DD 0\t\t\t ; Source Function Call\n"); fprintf(fp, "R_DFC\t DD 0\t\t\t ; Destination Function Call\n"); fprintf(fp, "R_USP\t DD 0\t\t\t ; User Stack\n"); fprintf(fp, "R_VBR\t DD 0\t\t\t ; Vector Base\n"); fprintf(fp, "asmbank\t DD 0\n\n"); fprintf(fp, "CPUversion\t DD 0\n\n"); fprintf(fp, "FullPC\t DD 0\n\n"); /* Extra space for variables mame uses for debugger */ fprintf(fp, "\t\t DD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n"); fprintf(fp, "\t\t DD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n"); fprintf(fp, "\t\t DD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n"); fprintf(fp, "\t\t DD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n"); fprintf(fp, "\t\t DD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n"); fprintf(fp, "\t\t DD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n"); fprintf(fp, "\t\t DD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n"); fprintf(fp, "\t\t DD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n\n"); /* Safe Memory Locations */ fprintf(fp, "\t\t ALIGN 16\n"); fprintf(fp, "\n\nIntelFlag\t\t\t\t; Intel Flag Lookup Table\n"); fprintf(fp, "\t\t DD 0000h,0001h,0800h,0801h,0040h,0041h,0840h,0841h\n"); fprintf(fp, "\t\t DD 0080h,0081h,0880h,0881h,00C0h,00C1h,08C0h,08C1h\n"); fprintf(fp, "\t\t DD 0100h,0101h,0900h,0901h,0140h,0141h,0940h,0941h\n"); fprintf(fp, "\t\t DD 0180h,0181h,0980h,0981h,01C0h,01C1h,09C0h,09C1h\n"); #if 0 fprintf(fp, "\n\nImmTable\n"); fprintf(fp, "\t\t DD 8,1,2,3,4,5,6,7\n\n"); #endif /* Exception Timing Table */ fprintf(fp, "exception_cycles\n"); fprintf(fp, "\t\t DB 0, 0, 0, 0, 38, 42, 44, 38, 38, 0, 38, 38, 0, 0, 0, 0\n"); fprintf(fp, "\t\t DB 0, 0, 0, 0, 0, 0, 0, 0, 46, 46, 46, 46, 46, 46, 46, 46\n"); fprintf(fp, "\t\t DB 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38\n\n"); fprintf(fp, "; RLE Compressed Jump Table\n\n"); fprintf(fp, "%s_COMPTABLE\n\n", CPUtype); fprintf(fp, "%cinclude '%s'\n\n",'%', comptab); fprintf(fp, "\t\tDW 0,0,0\n\n"); /* If using Windows, put the table area in .data section (Kenjo) */ #ifdef WIN32 fprintf(fp, "%s_OPCODETABLE\tTIMES 65536 DD 0\n\n", CPUtype); #else #ifdef OS2 fprintf(fp, "\t\t SECTION tempdata USE32 FLAT CLASS=BSS\n\n"); #else fprintf(fp, "\t\t SECTION .bss\n"); #endif fprintf(fp, "%s_OPCODETABLE\tRESD 65536\n\n", CPUtype); #endif } void EmitCode(void) { CodeSegmentBegin(); /* Instructions */ moveinstructions(); /* 1000 to 3FFF MOVE.X */ immediate(); /* 0### XXX.I */ bitdynamic(); /* 0### dynamic bit operations */ movep(); /* 0### Move Peripheral */ bitstatic(); /* 08## static bit operations */ LoadEffectiveAddress(); /* 4### */ PushEffectiveAddress(); /* ???? */ movesr(); /* 4#C# */ opcode5(); /* 5000 to 5FFF ADDQ,SUBQ,Scc and DBcc */ branchinstructions(); /* 6000 to 6FFF Bcc,BSR */ moveq(); /* 7000 to 7FFF MOVEQ */ abcd_sbcd(); /* 8### Decimal Add/Sub */ typelogicalmath(); /* Various ranges */ addx_subx(); divides(); swap(); not(); /* also neg negx clr */ moveusp(); chk(); exg(); cmpm(); mul(); ReturnandRestore(); rts(); jmp_jsr(); nbcd(); tas(); trap(); trapv(); reset(); nop(); stop(); ext(); ReturnFromException(); tst(); movem_reg_ea(); movem_ea_reg(); link(); unlinkasm(); asl_asr(); /* E### Shift Commands */ asl_asr_ea(); roxl_roxr(); roxl_roxr_ea(); lsl_lsr(); lsl_lsr_ea(); rol_ror(); rol_ror_ea(); LineA(); /* A000 to AFFF Line A */ LineF(); /* F000 to FFFF Line F */ illegal_opcode(); ReturnandDeallocate(); /* 68010 Commands */ MoveControlRegister(); MoveAddressSpace(); if(CPU==2) /* 68020 Commands */ { divl(); mull(); bfext(); } CodeSegmentEnd(); } int main(int argc, char **argv) { int dwLoop; printf("\nMake68K - V%s - Copyright 1998, Mike Coates ([email protected])\n", VERSION); printf(" 1999, & Darren Olafson ([email protected])\n"); printf(" 2000\n"); if (argc != 4 && argc != 5) { printf("Usage: %s outfile jumptable-outfile type [ppro]\n", argv[0]); exit(1); } printf("Building 680%s 2001\n\n",argv[3]); for (dwLoop=0;dwLoop<65536;) OpcodeArray[dwLoop++] = -2; codebuf=malloc(64); if (!codebuf) { printf ("Memory allocation error\n"); exit(3); } /* Emit the code */ fp = fopen(argv[1], "w"); if (!fp) { fprintf(stderr, "Can't open %s for writing\n", argv[1]); exit(1); } comptab = argv[2]; CPUtype = malloc(64); sprintf(CPUtype,"%sM680%s", PREF, argv[3]); if(argv[3][0]=='2') CPU = 2; if(argc > 4 && !strcmp(argv[4], "ppro")) { ppro = 1; printf("Generating ppro opcodes\n"); } EmitCode(); fclose(fp); printf("\n%d Unique Opcodes\n",Opcount); /* output Jump table to separate file */ fp = fopen(argv[2], "w"); if (!fp) { fprintf(stderr, "Can't open %s for writing\n", argv[2]); exit(1); } JumpTable(); fclose(fp); exit(0); }
the_stack_data/432327.c
/* Generated by CIL v. 1.7.0 */ /* print_CIL_Input is false */ struct _IO_FILE; struct timeval; extern void signal(int sig , void *func ) ; extern float strtof(char const *str , char const *endptr ) ; typedef struct _IO_FILE FILE; extern int atoi(char const *s ) ; extern double strtod(char const *str , char const *endptr ) ; extern int fclose(void *stream ) ; extern void *fopen(char const *filename , char const *mode ) ; extern void abort() ; extern void exit(int status ) ; extern int raise(int sig ) ; extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ; extern int strcmp(char const *a , char const *b ) ; extern int rand() ; extern unsigned long strtoul(char const *str , char const *endptr , int base ) ; void RandomFunc(unsigned char input[1] , unsigned char output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; void megaInit(void) { { } } int main(int argc , char *argv[] ) { unsigned char input[1] ; unsigned char output[1] ; int randomFuns_i5 ; unsigned char randomFuns_value6 ; int randomFuns_main_i7 ; { megaInit(); if (argc != 2) { printf("Call this program with %i arguments\n", 1); exit(-1); } else { } randomFuns_i5 = 0; while (randomFuns_i5 < 1) { randomFuns_value6 = (unsigned char )strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 206) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%u\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void RandomFunc(unsigned char input[1] , unsigned char output[1] ) { unsigned char state[1] ; unsigned char local2 ; unsigned char local1 ; { state[0UL] = (input[0UL] - 51238316UL) - (unsigned char)191; local1 = 0UL; while (local1 < (unsigned char)0) { local2 = 0UL; while (local2 < (unsigned char)0) { state[local1] |= state[local2]; state[0UL] |= (state[local2] & (unsigned char)31) << 3UL; local2 += 2UL; } local1 ++; } output[0UL] = state[0UL] + (787497705UL >> (unsigned char)255); } }
the_stack_data/94501.c
/* * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * * Copyright (c) 2021 Damien P. George * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include <string.h> // These memory functions are needed when the garbage collector is disabled. // A full implementation should be provided, or the garbage collector enabled. // The functions here are very simple. extern char _heap_start; void *malloc(size_t n) { static char *cur_heap = NULL; if (cur_heap == NULL) { cur_heap = &_heap_start; } void *ptr = cur_heap; cur_heap += (n + 7) & ~7; return ptr; } void *realloc(void *ptr, size_t size) { void *ptr2 = malloc(size); if (ptr && size) { memcpy(ptr2, ptr, size); // size may be greater than ptr's region, do copy anyway } return ptr2; } void free(void *p) { } // These standard string functions are needed by the runtime, and can be // provided either by the system or lib/libc/string0.c. The implementations // here are very simple. int memcmp(const void *s1, const void *s2, size_t n) { const unsigned char *ss1 = s1, *ss2 = s2; while (n--) { int c = *ss1++ - *ss2++; if (c) { return c; } } return 0; } void *memcpy(void *dest, const void *src, size_t n) { return memmove(dest, src, n); } void *memmove(void *dest, const void *src, size_t n) { unsigned char *d = dest; const unsigned char *s = src; if (s < d && d < s + n) { // Need to copy backwards. d += n - 1; s += n - 1; while (n--) { *d-- = *s--; } } else { // Can copy forwards. while (n--) { *d++ = *s++; } } return dest; } void *memset(void *s, int c, size_t n) { unsigned char *ss = s; while (n--) { *ss++ = c; } return s; } char *strchr(const char *s, int c) { while (*s) { if (*s == c) { return (char *)s; } ++s; } return NULL; } int strcmp(const char *s1, const char *s2) { while (*s1 && *s2) { int c = *s1++ - *s2++; if (c) { return c; } } return *s1 - *s2; } size_t strlen(const char *s) { const char *ss = s; while (*ss) { ++ss; } return ss - s; } // Dummy functions, used just in a couple of places. char *strstr(const char *where, const char *what) { return NULL; } void *memchr(const void *s, int c, size_t n) { return NULL; }
the_stack_data/156392483.c
/* This file was automatically generated by CasADi. The CasADi copyright holders make no ownership claim of its contents. */ #ifdef __cplusplus extern "C" { #endif /* How to prefix internal symbols */ #ifdef CASADI_CODEGEN_PREFIX #define CASADI_NAMESPACE_CONCAT(NS, ID) _CASADI_NAMESPACE_CONCAT(NS, ID) #define _CASADI_NAMESPACE_CONCAT(NS, ID) NS ## ID #define CASADI_PREFIX(ID) CASADI_NAMESPACE_CONCAT(CODEGEN_PREFIX, ID) #else #define CASADI_PREFIX(ID) Translational_drone_expl_vde_forw_ ## ID #endif #include <math.h> #ifndef casadi_real #define casadi_real double #endif #ifndef casadi_int #define casadi_int int #endif /* Add prefix to internal symbols */ #define casadi_clear CASADI_PREFIX(clear) #define casadi_copy CASADI_PREFIX(copy) #define casadi_f0 CASADI_PREFIX(f0) #define casadi_project CASADI_PREFIX(project) #define casadi_s0 CASADI_PREFIX(s0) #define casadi_s1 CASADI_PREFIX(s1) #define casadi_s10 CASADI_PREFIX(s10) #define casadi_s11 CASADI_PREFIX(s11) #define casadi_s2 CASADI_PREFIX(s2) #define casadi_s3 CASADI_PREFIX(s3) #define casadi_s4 CASADI_PREFIX(s4) #define casadi_s5 CASADI_PREFIX(s5) #define casadi_s6 CASADI_PREFIX(s6) #define casadi_s7 CASADI_PREFIX(s7) #define casadi_s8 CASADI_PREFIX(s8) #define casadi_s9 CASADI_PREFIX(s9) #define casadi_trans CASADI_PREFIX(trans) /* Symbol visibility in DLLs */ #ifndef CASADI_SYMBOL_EXPORT #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) #if defined(STATIC_LINKED) #define CASADI_SYMBOL_EXPORT #else #define CASADI_SYMBOL_EXPORT __declspec(dllexport) #endif #elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) #define CASADI_SYMBOL_EXPORT __attribute__ ((visibility ("default"))) #else #define CASADI_SYMBOL_EXPORT #endif #endif void casadi_copy(const casadi_real* x, casadi_int n, casadi_real* y) { casadi_int i; if (y) { if (x) { for (i=0; i<n; ++i) *y++ = *x++; } else { for (i=0; i<n; ++i) *y++ = 0.; } } } void casadi_clear(casadi_real* x, casadi_int n) { casadi_int i; if (x) { for (i=0; i<n; ++i) *x++ = 0; } } void casadi_trans(const casadi_real* x, const casadi_int* sp_x, casadi_real* y, const casadi_int* sp_y, casadi_int* tmp) { casadi_int ncol_x, nnz_x, ncol_y, k; const casadi_int* row_x, *colind_y; ncol_x = sp_x[1]; nnz_x = sp_x[2 + ncol_x]; row_x = sp_x + 2 + ncol_x+1; ncol_y = sp_y[1]; colind_y = sp_y+2; for (k=0; k<ncol_y; ++k) tmp[k] = colind_y[k]; for (k=0; k<nnz_x; ++k) { y[tmp[row_x[k]]++] = x[k]; } } void casadi_project(const casadi_real* x, const casadi_int* sp_x, casadi_real* y, const casadi_int* sp_y, casadi_real* w) { casadi_int ncol_x, ncol_y, i, el; const casadi_int *colind_x, *row_x, *colind_y, *row_y; ncol_x = sp_x[1]; colind_x = sp_x+2; row_x = sp_x + 2 + ncol_x+1; ncol_y = sp_y[1]; colind_y = sp_y+2; row_y = sp_y + 2 + ncol_y+1; for (i=0; i<ncol_x; ++i) { for (el=colind_y[i]; el<colind_y[i+1]; ++el) w[row_y[el]] = 0; for (el=colind_x[i]; el<colind_x[i+1]; ++el) w[row_x[el]] = x[el]; for (el=colind_y[i]; el<colind_y[i+1]; ++el) y[el] = w[row_y[el]]; } } static const casadi_int casadi_s0[3] = {2, 7, 11}; static const casadi_int casadi_s1[3] = {3, 8, 12}; static const casadi_int casadi_s2[21] = {6, 5, 0, 3, 5, 8, 11, 13, 3, 4, 5, 3, 4, 3, 4, 5, 3, 4, 5, 3, 4}; static const casadi_int casadi_s3[22] = {5, 6, 0, 0, 0, 0, 5, 10, 13, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 2, 3}; static const casadi_int casadi_s4[36] = {6, 5, 0, 6, 11, 17, 23, 28, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4}; static const casadi_int casadi_s5[23] = {6, 5, 0, 3, 6, 9, 12, 15, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2}; static const casadi_int casadi_s6[10] = {6, 1, 0, 6, 0, 1, 2, 3, 4, 5}; static const casadi_int casadi_s7[45] = {6, 6, 0, 6, 12, 18, 24, 30, 36, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5}; static const casadi_int casadi_s8[38] = {6, 5, 0, 6, 12, 18, 24, 30, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5}; static const casadi_int casadi_s9[9] = {5, 1, 0, 5, 0, 1, 2, 3, 4}; static const casadi_int casadi_s10[3] = {0, 0, 0}; static const casadi_int casadi_s11[27] = {6, 6, 0, 3, 6, 9, 12, 15, 18, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2}; /* Translational_drone_expl_vde_forw:(i0[6],i1[6x6],i2[6x5],i3[5],i4[])->(o0[6],o1[6x6,18nz],o2[6x5,28nz]) */ static int casadi_f0(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem) { casadi_int i; casadi_real *rr, *ss; const casadi_int *cii; const casadi_real *cs; casadi_real w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, *w12=w+18, *w13=w+54, *w14=w+60, *w15=w+66, *w16=w+72, *w17=w+78, *w18=w+84, w19, *w20=w+91, w24, *w25=w+105, *w26=w+108, *w28=w+111, *w29=w+113, *w30=w+115, *w31=w+128, *w32=w+156, *w33=w+186, *w34=w+189, *w35=w+192, *w36=w+195, *w37=w+210; /* #0: @0 = input[0][3] */ w0 = arg[0] ? arg[0][3] : 0; /* #1: output[0][0] = @0 */ if (res[0]) res[0][0] = w0; /* #2: @0 = input[0][4] */ w0 = arg[0] ? arg[0][4] : 0; /* #3: output[0][1] = @0 */ if (res[0]) res[0][1] = w0; /* #4: @0 = input[0][5] */ w0 = arg[0] ? arg[0][5] : 0; /* #5: output[0][2] = @0 */ if (res[0]) res[0][2] = w0; /* #6: @0 = input[3][1] */ w0 = arg[3] ? arg[3][1] : 0; /* #7: @1 = input[3][3] */ w1 = arg[3] ? arg[3][3] : 0; /* #8: @2 = (@0*@1) */ w2 = (w0*w1); /* #9: @3 = input[3][2] */ w3 = arg[3] ? arg[3][2] : 0; /* #10: @4 = input[3][4] */ w4 = arg[3] ? arg[3][4] : 0; /* #11: @5 = (@3*@4) */ w5 = (w3*w4); /* #12: @2 = (@2+@5) */ w2 += w5; /* #13: @2 = (2.*@2) */ w2 = (2.* w2 ); /* #14: @5 = input[3][0] */ w5 = arg[3] ? arg[3][0] : 0; /* #15: @6 = (@2*@5) */ w6 = (w2*w5); /* #16: @7 = 0.027 */ w7 = 2.7000000000000000e-02; /* #17: @6 = (@6/@7) */ w6 /= w7; /* #18: output[0][3] = @6 */ if (res[0]) res[0][3] = w6; /* #19: @6 = (@1*@4) */ w6 = (w1*w4); /* #20: @7 = (@0*@3) */ w7 = (w0*w3); /* #21: @6 = (@6-@7) */ w6 -= w7; /* #22: @6 = (2.*@6) */ w6 = (2.* w6 ); /* #23: @7 = (@6*@5) */ w7 = (w6*w5); /* #24: @8 = 0.027 */ w8 = 2.7000000000000000e-02; /* #25: @7 = (@7/@8) */ w7 /= w8; /* #26: output[0][4] = @7 */ if (res[0]) res[0][4] = w7; /* #27: @7 = 1 */ w7 = 1.; /* #28: @8 = (2.*@3) */ w8 = (2.* w3 ); /* #29: @9 = (@8*@3) */ w9 = (w8*w3); /* #30: @7 = (@7-@9) */ w7 -= w9; /* #31: @9 = (2.*@1) */ w9 = (2.* w1 ); /* #32: @10 = (@9*@1) */ w10 = (w9*w1); /* #33: @7 = (@7-@10) */ w7 -= w10; /* #34: @10 = (@7*@5) */ w10 = (w7*w5); /* #35: @11 = 0.027 */ w11 = 2.7000000000000000e-02; /* #36: @10 = (@10/@11) */ w10 /= w11; /* #37: @11 = 9.81 */ w11 = 9.8100000000000005e+00; /* #38: @10 = (@10-@11) */ w10 -= w11; /* #39: output[0][5] = @10 */ if (res[0]) res[0][5] = w10; /* #40: @12 = input[1][0] */ casadi_copy(arg[1], 36, w12); /* #41: {@13, @14, @15, @16, @17, @18} = horzsplit(@12) */ casadi_copy(w12, 6, w13); casadi_copy(w12+6, 6, w14); casadi_copy(w12+12, 6, w15); casadi_copy(w12+18, 6, w16); casadi_copy(w12+24, 6, w17); casadi_copy(w12+30, 6, w18); /* #42: {NULL, NULL, NULL, @10, @11, @19} = vertsplit(@13) */ w10 = w13[3]; w11 = w13[4]; w19 = w13[5]; /* #43: output[1][0] = @10 */ if (res[1]) res[1][0] = w10; /* #44: output[1][1] = @11 */ if (res[1]) res[1][1] = w11; /* #45: output[1][2] = @19 */ if (res[1]) res[1][2] = w19; /* #46: {NULL, NULL, NULL, @19, @11, @10} = vertsplit(@14) */ w19 = w14[3]; w11 = w14[4]; w10 = w14[5]; /* #47: output[1][3] = @19 */ if (res[1]) res[1][3] = w19; /* #48: output[1][4] = @11 */ if (res[1]) res[1][4] = w11; /* #49: output[1][5] = @10 */ if (res[1]) res[1][5] = w10; /* #50: {NULL, NULL, NULL, @10, @11, @19} = vertsplit(@15) */ w10 = w15[3]; w11 = w15[4]; w19 = w15[5]; /* #51: output[1][6] = @10 */ if (res[1]) res[1][6] = w10; /* #52: output[1][7] = @11 */ if (res[1]) res[1][7] = w11; /* #53: output[1][8] = @19 */ if (res[1]) res[1][8] = w19; /* #54: {NULL, NULL, NULL, @19, @11, @10} = vertsplit(@16) */ w19 = w16[3]; w11 = w16[4]; w10 = w16[5]; /* #55: output[1][9] = @19 */ if (res[1]) res[1][9] = w19; /* #56: output[1][10] = @11 */ if (res[1]) res[1][10] = w11; /* #57: output[1][11] = @10 */ if (res[1]) res[1][11] = w10; /* #58: {NULL, NULL, NULL, @10, @11, @19} = vertsplit(@17) */ w10 = w17[3]; w11 = w17[4]; w19 = w17[5]; /* #59: output[1][12] = @10 */ if (res[1]) res[1][12] = w10; /* #60: output[1][13] = @11 */ if (res[1]) res[1][13] = w11; /* #61: output[1][14] = @19 */ if (res[1]) res[1][14] = w19; /* #62: {NULL, NULL, NULL, @19, @11, @10} = vertsplit(@18) */ w19 = w18[3]; w11 = w18[4]; w10 = w18[5]; /* #63: output[1][15] = @19 */ if (res[1]) res[1][15] = w19; /* #64: output[1][16] = @11 */ if (res[1]) res[1][16] = w11; /* #65: output[1][17] = @10 */ if (res[1]) res[1][17] = w10; /* #66: @20 = zeros(5x6,13nz) */ casadi_clear(w20, 13); /* #67: @21 = 00 */ /* #68: @22 = 00 */ /* #69: @23 = 00 */ /* #70: @10 = 37.037 */ w10 = 3.7037037037037038e+01; /* #71: @11 = ones(5x1,1nz) */ w11 = 1.; /* #72: {@19, NULL, NULL, NULL, NULL} = vertsplit(@11) */ w19 = w11; /* #73: @2 = (@2*@19) */ w2 *= w19; /* #74: @2 = (@10*@2) */ w2 = (w10*w2); /* #75: @11 = 37.037 */ w11 = 3.7037037037037038e+01; /* #76: @6 = (@6*@19) */ w6 *= w19; /* #77: @6 = (@11*@6) */ w6 = (w11*w6); /* #78: @24 = 37.037 */ w24 = 3.7037037037037038e+01; /* #79: @7 = (@7*@19) */ w7 *= w19; /* #80: @7 = (@24*@7) */ w7 = (w24*w7); /* #81: @25 = vertcat(@21, @22, @23, @2, @6, @7) */ rr=w25; *rr++ = w2; *rr++ = w6; *rr++ = w7; /* #82: @26 = @25[:3] */ for (rr=w26, ss=w25+0; ss!=w25+3; ss+=1) *rr++ = *ss; /* #83: (@20[:15:5] = @26) */ for (rr=w20+0, ss=w26; rr!=w20+15; rr+=5) *rr = *ss++; /* #84: @21 = 00 */ /* #85: @22 = 00 */ /* #86: @23 = 00 */ /* #87: @2 = ones(5x1,1nz) */ w2 = 1.; /* #88: {NULL, @6, NULL, NULL, NULL} = vertsplit(@2) */ w6 = w2; /* #89: @2 = (@1*@6) */ w2 = (w1*w6); /* #90: @2 = (2.*@2) */ w2 = (2.* w2 ); /* #91: @2 = (@5*@2) */ w2 = (w5*w2); /* #92: @2 = (@10*@2) */ w2 = (w10*w2); /* #93: @6 = (@3*@6) */ w6 = (w3*w6); /* #94: @6 = (-@6) */ w6 = (- w6 ); /* #95: @6 = (2.*@6) */ w6 = (2.* w6 ); /* #96: @6 = (@5*@6) */ w6 = (w5*w6); /* #97: @6 = (@11*@6) */ w6 = (w11*w6); /* #98: @27 = 00 */ /* #99: @28 = vertcat(@21, @22, @23, @2, @6, @27) */ rr=w28; *rr++ = w2; *rr++ = w6; /* #100: @29 = @28[:2] */ for (rr=w29, ss=w28+0; ss!=w28+2; ss+=1) *rr++ = *ss; /* #101: (@20[1:11:5] = @29) */ for (rr=w20+1, ss=w29; rr!=w20+11; rr+=5) *rr = *ss++; /* #102: @21 = 00 */ /* #103: @22 = 00 */ /* #104: @23 = 00 */ /* #105: @2 = ones(5x1,1nz) */ w2 = 1.; /* #106: {NULL, NULL, @6, NULL, NULL} = vertsplit(@2) */ w6 = w2; /* #107: @2 = (@4*@6) */ w2 = (w4*w6); /* #108: @2 = (2.*@2) */ w2 = (2.* w2 ); /* #109: @2 = (@5*@2) */ w2 = (w5*w2); /* #110: @2 = (@10*@2) */ w2 = (w10*w2); /* #111: @7 = (@0*@6) */ w7 = (w0*w6); /* #112: @7 = (-@7) */ w7 = (- w7 ); /* #113: @7 = (2.*@7) */ w7 = (2.* w7 ); /* #114: @7 = (@5*@7) */ w7 = (w5*w7); /* #115: @7 = (@11*@7) */ w7 = (w11*w7); /* #116: @19 = (2.*@6) */ w19 = (2.* w6 ); /* #117: @19 = (@3*@19) */ w19 = (w3*w19); /* #118: @8 = (@8*@6) */ w8 *= w6; /* #119: @19 = (@19+@8) */ w19 += w8; /* #120: @19 = (@5*@19) */ w19 = (w5*w19); /* #121: @19 = (@24*@19) */ w19 = (w24*w19); /* #122: @19 = (-@19) */ w19 = (- w19 ); /* #123: @26 = vertcat(@21, @22, @23, @2, @7, @19) */ rr=w26; *rr++ = w2; *rr++ = w7; *rr++ = w19; /* #124: @25 = @26[:3] */ for (rr=w25, ss=w26+0; ss!=w26+3; ss+=1) *rr++ = *ss; /* #125: (@20[2, 7, 11] = @25) */ for (cii=casadi_s0, rr=w20, ss=w25; cii!=casadi_s0+3; ++cii, ++ss) if (*cii>=0) rr[*cii] = *ss; /* #126: @21 = 00 */ /* #127: @22 = 00 */ /* #128: @23 = 00 */ /* #129: @2 = ones(5x1,1nz) */ w2 = 1.; /* #130: {NULL, NULL, NULL, @7, NULL} = vertsplit(@2) */ w7 = w2; /* #131: @0 = (@0*@7) */ w0 *= w7; /* #132: @0 = (2.*@0) */ w0 = (2.* w0 ); /* #133: @0 = (@5*@0) */ w0 = (w5*w0); /* #134: @0 = (@10*@0) */ w0 = (w10*w0); /* #135: @4 = (@4*@7) */ w4 *= w7; /* #136: @4 = (2.*@4) */ w4 = (2.* w4 ); /* #137: @4 = (@5*@4) */ w4 = (w5*w4); /* #138: @4 = (@11*@4) */ w4 = (w11*w4); /* #139: @2 = (2.*@7) */ w2 = (2.* w7 ); /* #140: @2 = (@1*@2) */ w2 = (w1*w2); /* #141: @9 = (@9*@7) */ w9 *= w7; /* #142: @2 = (@2+@9) */ w2 += w9; /* #143: @2 = (@5*@2) */ w2 = (w5*w2); /* #144: @24 = (@24*@2) */ w24 *= w2; /* #145: @24 = (-@24) */ w24 = (- w24 ); /* #146: @25 = vertcat(@21, @22, @23, @0, @4, @24) */ rr=w25; *rr++ = w0; *rr++ = w4; *rr++ = w24; /* #147: @26 = @25[:3] */ for (rr=w26, ss=w25+0; ss!=w25+3; ss+=1) *rr++ = *ss; /* #148: (@20[3, 8, 12] = @26) */ for (cii=casadi_s1, rr=w20, ss=w26; cii!=casadi_s1+3; ++cii, ++ss) if (*cii>=0) rr[*cii] = *ss; /* #149: @21 = 00 */ /* #150: @22 = 00 */ /* #151: @23 = 00 */ /* #152: @0 = ones(5x1,1nz) */ w0 = 1.; /* #153: {NULL, NULL, NULL, NULL, @4} = vertsplit(@0) */ w4 = w0; /* #154: @3 = (@3*@4) */ w3 *= w4; /* #155: @3 = (2.*@3) */ w3 = (2.* w3 ); /* #156: @3 = (@5*@3) */ w3 = (w5*w3); /* #157: @10 = (@10*@3) */ w10 *= w3; /* #158: @1 = (@1*@4) */ w1 *= w4; /* #159: @1 = (2.*@1) */ w1 = (2.* w1 ); /* #160: @5 = (@5*@1) */ w5 *= w1; /* #161: @11 = (@11*@5) */ w11 *= w5; /* #162: @27 = 00 */ /* #163: @29 = vertcat(@21, @22, @23, @10, @11, @27) */ rr=w29; *rr++ = w10; *rr++ = w11; /* #164: @28 = @29[:2] */ for (rr=w28, ss=w29+0; ss!=w29+2; ss+=1) *rr++ = *ss; /* #165: (@20[4:14:5] = @28) */ for (rr=w20+4, ss=w28; rr!=w20+14; rr+=5) *rr = *ss++; /* #166: @30 = @20' */ casadi_trans(w20,casadi_s3, w30, casadi_s2, iw); /* #167: @31 = project(@30) */ casadi_project(w30, casadi_s2, w31, casadi_s4, w); /* #168: @32 = input[2][0] */ casadi_copy(arg[2], 30, w32); /* #169: {@18, @17, @16, @15, @14} = horzsplit(@32) */ casadi_copy(w32, 6, w18); casadi_copy(w32+6, 6, w17); casadi_copy(w32+12, 6, w16); casadi_copy(w32+18, 6, w15); casadi_copy(w32+24, 6, w14); /* #170: {NULL, NULL, NULL, @10, @11, @5} = vertsplit(@18) */ w10 = w18[3]; w11 = w18[4]; w5 = w18[5]; /* #171: @21 = 00 */ /* #172: @22 = 00 */ /* #173: @23 = 00 */ /* #174: @26 = vertcat(@10, @11, @5, @21, @22, @23) */ rr=w26; *rr++ = w10; *rr++ = w11; *rr++ = w5; /* #175: {NULL, NULL, NULL, @10, @11, @5} = vertsplit(@17) */ w10 = w17[3]; w11 = w17[4]; w5 = w17[5]; /* #176: @21 = 00 */ /* #177: @22 = 00 */ /* #178: @23 = 00 */ /* #179: @25 = vertcat(@10, @11, @5, @21, @22, @23) */ rr=w25; *rr++ = w10; *rr++ = w11; *rr++ = w5; /* #180: {NULL, NULL, NULL, @10, @11, @5} = vertsplit(@16) */ w10 = w16[3]; w11 = w16[4]; w5 = w16[5]; /* #181: @21 = 00 */ /* #182: @22 = 00 */ /* #183: @23 = 00 */ /* #184: @33 = vertcat(@10, @11, @5, @21, @22, @23) */ rr=w33; *rr++ = w10; *rr++ = w11; *rr++ = w5; /* #185: {NULL, NULL, NULL, @10, @11, @5} = vertsplit(@15) */ w10 = w15[3]; w11 = w15[4]; w5 = w15[5]; /* #186: @21 = 00 */ /* #187: @22 = 00 */ /* #188: @23 = 00 */ /* #189: @34 = vertcat(@10, @11, @5, @21, @22, @23) */ rr=w34; *rr++ = w10; *rr++ = w11; *rr++ = w5; /* #190: {NULL, NULL, NULL, @10, @11, @5} = vertsplit(@14) */ w10 = w14[3]; w11 = w14[4]; w5 = w14[5]; /* #191: @21 = 00 */ /* #192: @22 = 00 */ /* #193: @23 = 00 */ /* #194: @35 = vertcat(@10, @11, @5, @21, @22, @23) */ rr=w35; *rr++ = w10; *rr++ = w11; *rr++ = w5; /* #195: @36 = horzcat(@26, @25, @33, @34, @35) */ rr=w36; for (i=0, cs=w26; i<3; ++i) *rr++ = *cs++; for (i=0, cs=w25; i<3; ++i) *rr++ = *cs++; for (i=0, cs=w33; i<3; ++i) *rr++ = *cs++; for (i=0, cs=w34; i<3; ++i) *rr++ = *cs++; for (i=0, cs=w35; i<3; ++i) *rr++ = *cs++; /* #196: @37 = project(@36) */ casadi_project(w36, casadi_s5, w37, casadi_s4, w); /* #197: @31 = (@31+@37) */ for (i=0, rr=w31, cs=w37; i<28; ++i) (*rr++) += (*cs++); /* #198: output[2][0] = @31 */ casadi_copy(w31, 28, res[2]); return 0; } CASADI_SYMBOL_EXPORT int Translational_drone_expl_vde_forw(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem){ return casadi_f0(arg, res, iw, w, mem); } CASADI_SYMBOL_EXPORT int Translational_drone_expl_vde_forw_alloc_mem(void) { return 0; } CASADI_SYMBOL_EXPORT int Translational_drone_expl_vde_forw_init_mem(int mem) { return 0; } CASADI_SYMBOL_EXPORT void Translational_drone_expl_vde_forw_free_mem(int mem) { } CASADI_SYMBOL_EXPORT int Translational_drone_expl_vde_forw_checkout(void) { return 0; } CASADI_SYMBOL_EXPORT void Translational_drone_expl_vde_forw_release(int mem) { } CASADI_SYMBOL_EXPORT void Translational_drone_expl_vde_forw_incref(void) { } CASADI_SYMBOL_EXPORT void Translational_drone_expl_vde_forw_decref(void) { } CASADI_SYMBOL_EXPORT casadi_int Translational_drone_expl_vde_forw_n_in(void) { return 5;} CASADI_SYMBOL_EXPORT casadi_int Translational_drone_expl_vde_forw_n_out(void) { return 3;} CASADI_SYMBOL_EXPORT casadi_real Translational_drone_expl_vde_forw_default_in(casadi_int i){ switch (i) { default: return 0; } } CASADI_SYMBOL_EXPORT const char* Translational_drone_expl_vde_forw_name_in(casadi_int i){ switch (i) { case 0: return "i0"; case 1: return "i1"; case 2: return "i2"; case 3: return "i3"; case 4: return "i4"; default: return 0; } } CASADI_SYMBOL_EXPORT const char* Translational_drone_expl_vde_forw_name_out(casadi_int i){ switch (i) { case 0: return "o0"; case 1: return "o1"; case 2: return "o2"; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* Translational_drone_expl_vde_forw_sparsity_in(casadi_int i) { switch (i) { case 0: return casadi_s6; case 1: return casadi_s7; case 2: return casadi_s8; case 3: return casadi_s9; case 4: return casadi_s10; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* Translational_drone_expl_vde_forw_sparsity_out(casadi_int i) { switch (i) { case 0: return casadi_s6; case 1: return casadi_s11; case 2: return casadi_s4; default: return 0; } } CASADI_SYMBOL_EXPORT int Translational_drone_expl_vde_forw_work(casadi_int *sz_arg, casadi_int* sz_res, casadi_int *sz_iw, casadi_int *sz_w) { if (sz_arg) *sz_arg = 11; if (sz_res) *sz_res = 9; if (sz_iw) *sz_iw = 6; if (sz_w) *sz_w = 238; return 0; } #ifdef __cplusplus } /* extern "C" */ #endif
the_stack_data/1204904.c
/* Generator of floating point tests. How to compile for and use under DOS: smlrcc -dosp genfp1.c -o genfp1.exe genfp1.exe >testfp1.c smlrcc -dosp testfp1.c -o testfp1.exe testfp1.exe How to compile for and use under Windows: smlrcc -win genfp1.c -o genfp1.exe genfp1.exe >testfp1.c smlrcc -win testfp1.c -o testfp1.exe testfp1.exe How to compile for and use under Linux: smlrcc -linux genfp1.c -o genfp1 ./genfp1 >testfp1.c smlrcc -linux testfp1.c -o testfp1 ./testfp1 */ #include <stdio.h> #include <string.h> #include <stdlib.h> typedef enum { fvNan, fv_Inf, fv_1, fv_0, fv0, fv1, fvInf, fvCnt } FloatVal; char* FloatValConstText[fvCnt] = { "(0.0f/0.0f)", "(-1.0f/0.0f)", "(-1.0f)", "(-0.0f)", "(+0.0f)", "(+1.0f)", "(+1.0f/0.0f)" }; char* FloatValConstName[fvCnt] = { "FNAN", "F_INF", "F_1", "F_0", "F0", "F1", "FINF" }; char* FloatValNonConstName[fvCnt] = { "fnan", "f_inf", "f_1", "f_0", "f0", "f1", "finf" }; typedef enum { coLT, coLE, coEQ, coGE, coGT, coNE, coCnt } CmpOperator; char* CmpOperatorText[coCnt] = { "<", "<=", "==", ">=", ">", "!=" }; int Fcmp(FloatVal a, FloatVal b, int NanVal) { if (a == fvNan || b == fvNan) return NanVal; // -0.0 == +0.0 if (a == fv_0) a = fv0; if (b == fv_0) b = fv0; if (a < b) return -1; if (a > b) return +1; return 0; } int FcmpOp(FloatVal a, FloatVal b, CmpOperator op) { int NanVal = (op == coGE || op == coGT) ? -1 : +1; int r = Fcmp(a, b, NanVal); switch (op) { case coLT: return r < 0; case coLE: return r <= 0; case coEQ: return r == 0; case coGE: return r >= 0; case coGT: return r > 0; default: case coNE: return r != 0; } } void GenDefs(int raw) { int i; if (!raw) { puts("#include <stdio.h>"); puts("#include <stdlib.h>\n"); } for (i = 0; i < fvCnt; i++) { printf("#define %s %s\n", FloatValConstName[i], FloatValConstText[i]); printf("float %s = %s;\n", FloatValNonConstName[i], FloatValConstName[i]); } puts(""); puts("float f0_5 = 0.5f;"); puts("float f1_5 = 1.5f;"); puts("int i0 = 0;"); puts("int i1 = 1;"); puts("int i4 = 4;"); puts(""); } void GenArithm(void) { int lidx, ridx; puts("void arithm(void)\n{"); puts(" int error = 0;\n"); for (lidx = 0; lidx < 4; lidx++) for (ridx = 0; ridx < 4; ridx++) { static char* v[] = { "1.5f", "f1_5", "4", "i4" }; static char* vdiv[] = { "0.5f", "f0_5", "4", "i4" }; printf(" if ((%s + %s) != %s) error = __LINE__;\n", v[lidx], v[ridx], (lidx < 2) ? ((ridx < 2) ? "3": "5.5f") : ((ridx < 2) ? "5.5f": "8")); printf(" if ((%s - %s) != %s) error = __LINE__;\n", v[lidx], v[ridx], (lidx < 2) ? ((ridx < 2) ? "0": "-2.5f") : ((ridx < 2) ? "2.5f": "0")); printf(" if ((%s * %s) != %s) error = __LINE__;\n", v[lidx], v[ridx], (lidx < 2) ? ((ridx < 2) ? "2.25f": "6") : ((ridx < 2) ? "6": "16")); printf(" if ((%s / %s) != %s) error = __LINE__;\n", vdiv[lidx], vdiv[ridx], (lidx < 2) ? ((ridx < 2) ? "1": "0.125f") : ((ridx < 2) ? "8": "1")); } puts("\n if (error)\n { printf(\"Test failed on line %d\\n\", error); abort(); }"); puts("}\n"); } void GenCmp(void) { int lconst, rconst, lidx, ridx, opidx; puts("void cmp(void)\n{"); puts(" int error = 0;\n"); // if (float cmp float) for (lconst = 0; lconst <= 1; lconst++) for (rconst = 0; rconst <= 1; rconst++) for (lidx = 0; lidx < fvCnt; lidx++) for (ridx = 0; ridx < fvCnt; ridx++) for (opidx = 0; opidx < coCnt; opidx++) { printf(" if ((%s %s %s) != %d) error = __LINE__;\n", lconst ? FloatValConstName[lidx] : FloatValNonConstName[lidx], CmpOperatorText[opidx], rconst ? FloatValConstName[ridx] : FloatValNonConstName[ridx], FcmpOp(lidx, ridx, opidx)); } // if (float cmp int) for (lconst = 0; lconst <= 1; lconst++) for (rconst = 0; rconst <= 1; rconst++) for (lidx = 0; lidx < fvCnt; lidx++) for (ridx = 0; ridx <= 1; ridx++) for (opidx = 0; opidx < coCnt; opidx++) { printf(" if ((%s %s %s) != %d) error = __LINE__;\n", lconst ? FloatValConstName[lidx] : FloatValNonConstName[lidx], CmpOperatorText[opidx], rconst ? (ridx ? "1" : "0") : (ridx ? "i1" : "i0"), FcmpOp(lidx, (ridx ? fv1 : fv0), opidx)); } // if (int cmp float) for (lconst = 0; lconst <= 1; lconst++) for (rconst = 0; rconst <= 1; rconst++) for (lidx = 0; lidx <= 1; lidx++) for (ridx = 0; ridx < fvCnt; ridx++) for (opidx = 0; opidx < coCnt; opidx++) { printf(" if ((%s %s %s) != %d) error = __LINE__;\n", lconst ? (lidx ? "1" : "0") : (lidx ? "i1" : "i0"), CmpOperatorText[opidx], rconst ? FloatValConstName[ridx] : FloatValNonConstName[ridx], FcmpOp((lidx ? fv1 : fv0), ridx, opidx)); } puts("\n if (error)\n { printf(\"Test failed on line %d\\n\", error); abort(); }"); puts("}\n"); } void GenCtrl(void) { int lconst, lidx, rconst, ridx, cconst, cidx, opidx; puts("void ctrl(void)\n{"); puts(" int error = 0;"); puts(" int cnt;\n"); // if (float) {} else {} for (lconst = 0; lconst <= 1; lconst++) for (lidx = 0; lidx < fvCnt; lidx++) { char *e[] = { "", "error = __LINE__;" }; int tru = FcmpOp(lidx, fv0, coNE); printf(" if (%s) { %s } else { %s }\n", lconst ? FloatValConstName[lidx] : FloatValNonConstName[lidx], e[!tru], e[tru]); } // for (;float;) {} for (lconst = 0; lconst <= 1; lconst++) for (lidx = 0; lidx < fvCnt; lidx++) { int tru = FcmpOp(lidx, fv0, coNE); printf(" for (cnt = 0; %s; ) { cnt++; break; } if (cnt != %d) error = __LINE__;\n", lconst ? FloatValConstName[lidx] : FloatValNonConstName[lidx], tru); } // while (float) {} for (lconst = 0; lconst <= 1; lconst++) for (lidx = 0; lidx < fvCnt; lidx++) { int tru = FcmpOp(lidx, fv0, coNE); printf(" cnt = 0; while (%s) { cnt++; break; } if (cnt != %d) error = __LINE__;\n", lconst ? FloatValConstName[lidx] : FloatValNonConstName[lidx], tru); } // do {} while (float); for (lconst = 0; lconst <= 1; lconst++) for (lidx = 0; lidx < fvCnt; lidx++) { int tru = FcmpOp(lidx, fv0, coNE); printf(" cnt = 0; do { if (cnt++) break; } while (%s); if (cnt != %d) error = __LINE__;\n", lconst ? FloatValConstName[lidx] : FloatValNonConstName[lidx], 1 + tru); } // float ||/&& float for (lconst = 0; lconst <= 1; lconst++) for (rconst = 0; rconst <= 1; rconst++) for (lidx = 0; lidx < fvCnt; lidx++) for (ridx = 0; ridx < fvCnt; ridx++) for (opidx = 0; opidx <= 1; opidx++) { int ltru = FcmpOp(lidx, fv0, coNE); int rtru = FcmpOp(ridx, fv0, coNE); int tru = opidx ? (ltru && rtru) : (ltru || rtru); printf(" if ((%s %s %s) != %d) error = __LINE__;\n", lconst ? FloatValConstName[lidx] : FloatValNonConstName[lidx], opidx ? "&&" : "||", rconst ? FloatValConstName[ridx] : FloatValNonConstName[ridx], tru); } // float ||/&& int // int ||/&& float for (lconst = 0; lconst <= 1; lconst++) for (rconst = 0; rconst <= 1; rconst++) for (lidx = 0; lidx < fvCnt; lidx++) for (ridx = 0; ridx <= 1; ridx++) for (opidx = 0; opidx <= 1; opidx++) { int tru = FcmpOp(lidx, fv0, coNE); tru = opidx ? (tru && ridx) : (tru || ridx); printf(" if ((%s %s %s) != %d) error = __LINE__;\n", lconst ? FloatValConstName[lidx] : FloatValNonConstName[lidx], opidx ? "&&" : "||", rconst ? (ridx ? "1" : "0") : (ridx ? "i1" : "i0"), tru); printf(" if ((%s %s %s) != %d) error = __LINE__;\n", rconst ? (ridx ? "1" : "0") : (ridx ? "i1" : "i0"), opidx ? "&&" : "||", lconst ? FloatValConstName[lidx] : FloatValNonConstName[lidx], tru); } // float ? int : float // float ? float : int // float ? float : float for (cconst = 0; cconst <= 1; cconst++) for (cidx = 0; cidx < fvCnt; cidx++) for (lidx = 0; lidx < 4; lidx++) for (ridx = 0; ridx < 4; ridx++) { static char* v[] = { "1.5f", "f1_5", "4", "i4" }; int tru = FcmpOp(cidx, fv0, coNE); char *l = v[lidx], *r = v[ridx]; printf(" if ((%s ? %s : %s) != %s) error = __LINE__;\n", cconst ? FloatValConstName[cidx] : FloatValNonConstName[cidx], l, r, tru ? l : r); } puts("\n if (error)\n { printf(\"Test failed on line %d\\n\", error); abort(); }"); puts("}\n"); } void GenCast(void) { puts("void cast(void)\n{"); puts(" int error = 0;"); puts(" float f_128_75 = -128.75f;"); puts(" float f127_75 = 127.75f;"); puts(" float f_0_75 = -0.75f;"); puts(" float f255_75 = 255.75f;"); puts(" float f_32768_75 = -32768.75f;"); puts(" float f32767_75 = 32767.75f;"); puts(" float f65535_75 = 65535.75f;"); puts(" float f_2147483648 = -2147483648.0f;"); puts(" float f2147483520 = 2147483520.0f;"); puts(" float f4294967040 = 4294967040.0f;"); puts(" int i_2147483648 = (-2147483647-1);"); puts(" int i2147483520 = 2147483520;"); puts(" unsigned u4294967040 = 4294967040u;"); puts(" int i2147483647 = 2147483647;"); puts(" unsigned u4294967295 = 4294967295u;\n"); puts(" if (((signed char)-128.75f == -128) != 1) error = __LINE__;"); puts(" if (((signed char)f_128_75 == -128) != 1) error = __LINE__;"); puts(" if (((signed char)+127.75f == +127) != 1) error = __LINE__;"); puts(" if (((signed char)f127_75 == +127) != 1) error = __LINE__;"); puts(" if (((unsigned char)-0.75f == 0) != 1) error = __LINE__;"); puts(" if (((unsigned char)f_0_75 == 0) != 1) error = __LINE__;"); puts(" if (((unsigned char)255.75f == 255) != 1) error = __LINE__;"); puts(" if (((unsigned char)f255_75 == 255) != 1) error = __LINE__;"); puts(" if (((short)-32768.75f == -32768) != 1) error = __LINE__;"); puts(" if (((short)f_32768_75 == -32768) != 1) error = __LINE__;"); puts(" if (((short)+32767.75f == +32767) != 1) error = __LINE__;"); puts(" if (((short)f32767_75 == +32767) != 1) error = __LINE__;"); puts(" if (((unsigned short)-0.75f == 0) != 1) error = __LINE__;"); puts(" if (((unsigned short)f_0_75 == 0) != 1) error = __LINE__;"); puts(" if (((unsigned short)65535.75f == 65535) != 1) error = __LINE__;"); puts(" if (((unsigned short)f65535_75 == 65535) != 1) error = __LINE__;"); puts(" if (((int)-2147483648.0f == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((int)f_2147483648 == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((int)+2147483520.0f == +2147483520) != 1) error = __LINE__;"); puts(" if (((int)f2147483520 == +2147483520) != 1) error = __LINE__;"); puts(" if (((unsigned)-0.75f == 0) != 1) error = __LINE__;"); puts(" if (((unsigned)f_0_75 == 0) != 1) error = __LINE__;"); puts(" if (((unsigned)4294967040.0f == 4294967040u) != 1) error = __LINE__;"); puts(" if (((unsigned)f4294967040 == 4294967040u) != 1) error = __LINE__;"); puts(" if (((float)(-2147483647-1) == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((float)i_2147483648 == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((float)+2147483520 == +2147483520) != 1) error = __LINE__;"); puts(" if (((float)i2147483520 == +2147483520) != 1) error = __LINE__;"); puts(" if (((float)4294967040u == 4294967040u) != 1) error = __LINE__;"); puts(" if (((float)u4294967040 == 4294967040u) != 1) error = __LINE__;"); puts(" if ((-(float)2147483647 == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if ((-(float)i2147483647 == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((float)4294967295u == -2.0f*(-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((float)u4294967295 == -2.0f*(-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((float)(float)(-2147483647-1) == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((float)(float)i_2147483648 == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((float)f_0_75 == -0.75f) != 1) error = __LINE__;"); puts("\n if (error)\n { printf(\"Test failed on line %d\\n\", error); abort(); }"); puts("}\n"); } void GenInit(void) { puts("void init(void)\n{"); puts(" int error = 0;"); puts(" float f_2147483648 = (-2147483647-1);"); puts(" static float sf_2147483648 = (-2147483647-1);"); puts(" float f4294967040 = 4294967040u;"); puts(" static float sf4294967040 = 4294967040u;"); puts(" int i_2147483648 = -2147483648.0f;"); puts(" static int si_2147483648 = -2147483648.0f;"); puts(" unsigned u4294967040 = 4294967040.0f;"); puts(" static unsigned su4294967040 = 4294967040.0f;\n"); puts(" if ((f_2147483648 == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if ((sf_2147483648 == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if ((f4294967040 == 4294967040u) != 1) error = __LINE__;"); puts(" if ((sf4294967040 == 4294967040u) != 1) error = __LINE__;"); puts(" if ((i_2147483648 == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if ((si_2147483648 == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if ((u4294967040 == 4294967040u) != 1) error = __LINE__;"); puts(" if ((su4294967040 == 4294967040u) != 1) error = __LINE__;"); puts("\n if (error)\n { printf(\"Test failed on line %d\\n\", error); abort(); }"); puts("}\n"); } void GenAssign(void) { puts("void assign(void)\n{"); puts(" int error = 0;"); puts(" float f;"); puts(" int i;"); puts(" unsigned u;\n"); puts(" if (((f = (-2147483647-1)) == -2147483648.0f) != 1) error = __LINE__;"); puts(" if (((f = 4294967040u) == 4294967040.0f) != 1) error = __LINE__;"); puts(" if (((i = -2147483648.0f) == (-2147483647-1)) != 1) error = __LINE__;"); puts(" if (((u = 4294967040.0f) == 4294967040u) != 1) error = __LINE__;"); puts("\n if (error)\n { printf(\"Test failed on line %d\\n\", error); abort(); }"); puts("}\n"); } void GenPass(void) { puts("void accept_i1(int* error, int line, int a)\n{\n if (a != 1) *error = line;\n}\n"); puts("void accept_u1(int* error, int line, unsigned a)\n{\n if (a != 1) *error = line;\n}\n"); puts("void accept_f1(int* error, int line, float a)\n{\n if (a != 1.0f) *error = line;\n}\n"); puts("void accept_i_2147483648(int* error, int line, int a)\n{\n if (a != (-2147483647-1)) *error = line;\n}\n"); puts("void accept_u4294967040(int* error, int line, unsigned a)\n{\n if (a != 4294967040u) *error = line;\n}\n"); puts("void accept_f_2147483648(int* error, int line, float a)\n{\n if (a != -2147483648.0f) *error = line;\n}\n"); puts("void accept_f4294967040(int* error, int line, float a)\n{\n if (a != 4294967040.0f) *error = line;\n}\n"); puts("void pass(void)\n{"); puts(" int error = 0;"); puts(" unsigned u1 = 1;"); puts(" float f_2147483648 = -2147483648.0f;"); puts(" float f4294967040 = 4294967040.0f;"); puts(" int i_2147483648 = (-2147483647-1);"); puts(" unsigned u4294967040 = 4294967040u;\n"); puts(" accept_i1(&error, __LINE__, F1);"); puts(" accept_i1(&error, __LINE__, f1);"); puts(" accept_u1(&error, __LINE__, F1);"); puts(" accept_u1(&error, __LINE__, f1);"); puts(" accept_f1(&error, __LINE__, F1);"); puts(" accept_f1(&error, __LINE__, f1);"); puts(" accept_f1(&error, __LINE__, i1);"); puts(" accept_f1(&error, __LINE__, u1);"); puts(" accept_f1(&error, __LINE__, 1);"); puts(" accept_f1(&error, __LINE__, 1u);"); puts(" accept_i_2147483648(&error, __LINE__, -2147483648.0f);"); puts(" accept_i_2147483648(&error, __LINE__, f_2147483648);"); puts(" accept_u4294967040(&error, __LINE__, 4294967040.0f);"); puts(" accept_u4294967040(&error, __LINE__, f4294967040);"); puts(" accept_f_2147483648(&error, __LINE__, (-2147483647-1));"); puts(" accept_f_2147483648(&error, __LINE__, i_2147483648);"); puts(" accept_f4294967040(&error, __LINE__, 4294967040u);"); puts(" accept_f4294967040(&error, __LINE__, u4294967040);"); // TBD??? passing into f() and f(blah, ...)??? puts("\n if (error)\n { printf(\"Test failed on line %d\\n\", error); abort(); }"); puts("}\n"); } void GenRet(void) { puts("signed char ret_sc_f(float a)\n{\n return a;\n}\n"); puts("signed char ret_sc__128_75(void)\n{\n return -128.75f;\n}\n"); puts("unsigned char ret_uc_f(float a)\n{\n return a;\n}\n"); puts("unsigned char ret_uc__0_75(void)\n{\n return -0.75f;\n}\n"); puts("unsigned char ret_uc_255_75(void)\n{\n return 255.75f;\n}\n"); puts("short ret_ss_f(float a)\n{\n return a;\n}\n"); puts("short ret_ss__32768_75(void)\n{\n return -32768.75f;\n}\n"); puts("unsigned short ret_us_f(float a)\n{\n return a;\n}\n"); puts("unsigned short ret_us__0_75(void)\n{\n return -0.75f;\n}\n"); puts("unsigned short ret_us_65535_75(void)\n{\n return 65535.75f;\n}\n"); puts("int ret_si_f(float a)\n{\n return a;\n}\n"); puts("int ret_si__2147483648_0(void)\n{\n return -2147483648.0f;\n}\n"); puts("unsigned ret_ui_f(float a)\n{\n return a;\n}\n"); puts("unsigned ret_ui_4294967040_0(void)\n{\n return 4294967040.0f;\n}\n"); puts("float ret_f_si(int a)\n{\n return a;\n}\n"); puts("float ret_f__2147483648(void)\n{\n return (-2147483647-1);\n}\n"); puts("float ret_f_ui(unsigned a)\n{\n return a;\n}\n"); puts("float ret_f_4294967040(void)\n{\n return 4294967040u;\n}\n"); puts("void ret(void)\n{"); puts(" int error = 0;"); puts(" if (ret_sc_f(-128.75f) != -128) error = __LINE__;"); puts(" if (ret_sc__128_75() != -128) error = __LINE__;"); puts(" if (ret_uc_f(255.75f) != +255) error = __LINE__;"); puts(" if (ret_uc__0_75() != 0) error = __LINE__;"); puts(" if (ret_uc_255_75() != +255) error = __LINE__;"); puts(" if (ret_ss_f(-32768.75f) != -32768) error = __LINE__;"); puts(" if (ret_ss__32768_75() != -32768) error = __LINE__;"); puts(" if (ret_us_f(65535.75f) != +65535) error = __LINE__;"); puts(" if (ret_us__0_75() != 0) error = __LINE__;"); puts(" if (ret_us_65535_75() != +65535) error = __LINE__;"); puts(" if (ret_si_f(-2147483648.0f) != (-2147483647-1)) error = __LINE__;"); puts(" if (ret_si__2147483648_0() != (-2147483647-1)) error = __LINE__;"); puts(" if (ret_ui_f(4294967040.0f) != +4294967040u) error = __LINE__;"); puts(" if (ret_ui_4294967040_0() != +4294967040u) error = __LINE__;"); puts(" if (ret_f_si((-2147483647-1)) != -2147483648.0f) error = __LINE__;"); puts(" if (ret_f__2147483648() != -2147483648.0f) error = __LINE__;"); puts(" if (ret_f_ui(+4294967040u) != 4294967040.0f) error = __LINE__;"); puts(" if (ret_f_4294967040() != 4294967040.0f) error = __LINE__;"); puts("\n if (error)\n { printf(\"Test failed on line %d\\n\", error); abort(); }"); puts("}\n"); } void GenMain(void) { puts("int main(void)\n{"); puts(" arithm();"); puts(" cmp();"); puts(" ctrl();"); puts(" cast();"); puts(" init();"); puts(" assign();"); puts(" pass();"); puts(" ret();"); puts(" puts(\"All tests passed.\");"); puts(" return 0;\n}"); } int main(int argc, char* argv[]) { int i, raw = 0; char* outname = NULL; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-raw")) { raw = 1; continue; } else if (!strcmp(argv[i], "-o")) { if (i + 1 < argc) { ++i; outname = argv[i]; continue; } } fprintf(stderr, "Invalid or unsupported command line option '%s'\n", argv[i]); return EXIT_FAILURE; } if (outname) freopen(outname, "w", stdout); GenDefs(raw); GenArithm(); GenCmp(); GenCtrl(); GenCast(); GenInit(); GenAssign(); GenPass(); GenRet(); GenMain(); return 0; }
the_stack_data/150140869.c
#include <stdio.h> //Copyright Chelin Tutorials. All Rights Reserved //http://chelintutorials.blogspot.com/ //Estructuras y Funciones //nueva manera typedef struct video{ char titulo [41]; int visitas; float tiempo; }video_t; //typedef struct video video_t; vieja manera //Esta funcion me crea un video video_t crear_video(){ //creo el nuevo video en blanco video_t nuevo_video; //asigno el titulo printf("\ningrese el nombre del video: "); fflush(stdin); gets(nuevo_video.titulo); //asigno el numero de visitas printf("\ningrese el numero de visitas: "); fflush(stdin); scanf(" %d",&nuevo_video.visitas); //asigno el tiempo printf("\ningrese el tiempo del video: "); fflush(stdin); scanf(" %f",&nuevo_video.tiempo); //devuevlo el video return nuevo_video; } //Esta funcion sirve para imprimir un video void imprimir_video(video_t video){ printf("%s , timepo: %g , visitas: %d \n",video.titulo,video.tiempo,video.visitas); } int main(void){ //creo 2 videos video_t v1 = crear_video(); video_t v2= crear_video(); //imprimimo los videos imprimir_video(v2); imprimir_video(v1); return 0; }
the_stack_data/95689.c
// Copyright 2020 Michael Rodriguez // // Permission to use, copy, modify, and /or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. // // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <assert.h> #include <stdlib.h> #include "memory.h" void* libgb_safe_malloc(const size_t size) { void* ptr = malloc(size); if (ptr == NULL) { abort(); return NULL; } return ptr; } void libgb_safe_free(void* ptr) { // `ptr` should never be `NULL` by the time we get here, even though // `free()` doesn't care. assert(ptr != NULL); free(ptr); ptr = NULL; }
the_stack_data/981391.c
#include <stdio.h> #define size 10 int a[size][size]; int vis[size]; int stack[size]; int top = 0; void push(int num) { top++; stack[top] = num; } int pop() { int t; t = stack[top]; top--; return t; } void dfs(int s, int n) { int p = stack[top], i, j; push(s); vis[s] = 1; p = pop(); if (p != 0) printf("%4d", p); while (p != 0) { for (i = 1; i <= n; i++) if (a[p][i] != 0 && vis[i] == 0) { push(i); vis[i] = 1; } p = pop(); if (p != 0) printf("%4d", p); } for (j = 1; j <= n; j++) if (vis[j] == 0) { top--; dfs(j, n); } } void main() { int v, e, i, j, k, l, n; printf("Enter no of vertices and edges: \n"); scanf("%d%d", &v, &e); for (i = 1; i <= v; i++) vis[i] = 0; for (i = 1; i <= v; i++) for (l = 1; l <= v; l++) a[i][l] = 0; for (i = 1; i <= e; i++) { printf("\nEnter pair of vertices\n"); scanf("%d%d", &j, &k); a[j][k] = a[k][j] = 1; } for (i = 1; i <= v; i++) { for (l = 1; l <= v; l++) printf("%4d", a[i][l]); printf("\n"); } printf("\nEnter the source node: "); scanf("%d", &n); dfs(n, v); printf("\n"); }
the_stack_data/87636926.c
/*********************************************************************** * * TUTORATO 3: Algoritmi elementari * ================================ * * * Quinto esercizio: radice quadrata * --------------------------------- * * 1) Completa il programma qui sotto in modo che calcoli * un'approssimazione della radice quadrato usando il metodo * babilonese. * * 2) Compila il programma con il comando: * * gcc -Wall -o es5 es5.c * * 3) Esegui il programma con il comando: * * ./es5 * * ed inserendo valori di prova. * ***********************************************************************/ #include <stdio.h> int main() { /* Dichiarazione e lettura dell'argomento della radice. */ double x; scanf("%lf", &x); /* Completa la funzione.*/ return 0; }
the_stack_data/53701.c
// RUN: %clang_cc1 -triple i686-unknown-unknown -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=I686-UNKNOWN %s // I686-UNKNOWN: target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128" // RUN: %clang_cc1 -triple i686-apple-darwin9 -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=I686-DARWIN %s // I686-DARWIN: target datalayout = "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:128-n8:16:32-S128" // RUN: %clang_cc1 -triple i686-unknown-win32 -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=I686-WIN32 %s // I686-WIN32: target datalayout = "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:32-n8:16:32-a:0:32-S32" // RUN: %clang_cc1 -triple i686-unknown-cygwin -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=I686-CYGWIN %s // I686-CYGWIN: target datalayout = "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:32-n8:16:32-a:0:32-S32" // RUN: %clang_cc1 -triple i686-pc-macho -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=I686-MACHO %s // I686-MACHO: target datalayout = "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128" // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=X86_64 %s // X86_64: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" // RUN: %clang_cc1 -triple xcore-unknown-unknown -emit-llvm -o - %s | \ // RUN: FileCheck --check-prefix=XCORE %s // XCORE: target datalayout = "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32-f64:32-a:0:32-n32" // RUN: %clang_cc1 -triple sparc-sun-solaris -emit-llvm -o - %s | \ // RUN: FileCheck %s --check-prefix=SPARC-V8 // SPARC-V8: target datalayout = "E-m:e-p:32:32-i64:64-f128:64-n32-S64" // RUN: %clang_cc1 -triple sparcv9-sun-solaris -emit-llvm -o - %s | \ // RUN: FileCheck %s --check-prefix=SPARC-V9 // SPARC-V9: target datalayout = "E-m:e-i64:64-n32:64-S128" // RUN: %clang_cc1 -triple mipsel-linux-gnu -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-32EL // RUN: %clang_cc1 -triple mipsisa32r6el-linux-gnu -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-32EL // MIPS-32EL: target datalayout = "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64" // RUN: %clang_cc1 -triple mips-linux-gnu -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-32EB // RUN: %clang_cc1 -triple mipsisa32r6-linux-gnu -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-32EB // MIPS-32EB: target datalayout = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64" // RUN: %clang_cc1 -triple mips64el-linux-gnu -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-64EL // RUN: %clang_cc1 -triple mips64el-linux-gnuabi64 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-64EL // RUN: %clang_cc1 -triple mipsisa64r6el-linux-gnu -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-64EL // RUN: %clang_cc1 -triple mipsisa64r6el-linux-gnuabi64 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-64EL // MIPS-64EL: target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128" // RUN: %clang_cc1 -triple mips64el-linux-gnu -o - -emit-llvm -target-abi n32 \ // RUN: %s | FileCheck %s -check-prefix=MIPS-64EL-N32 // RUN: %clang_cc1 -triple mips64el-linux-gnuabin32 -o - -emit-llvm \ // RUN: %s | FileCheck %s -check-prefix=MIPS-64EL-N32 // RUN: %clang_cc1 -triple mipsisa64r6el-linux-gnu -o - -emit-llvm -target-abi n32 \ // RUN: %s | FileCheck %s -check-prefix=MIPS-64EL-N32 // RUN: %clang_cc1 -triple mipsisa64r6el-linux-gnuabin32 -o - -emit-llvm \ // RUN: %s | FileCheck %s -check-prefix=MIPS-64EL-N32 // MIPS-64EL-N32: target datalayout = "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32:64-S128" // RUN: %clang_cc1 -triple mips64-linux-gnu -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-64EB // RUN: %clang_cc1 -triple mips64-linux-gnuabi64 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-64EB // RUN: %clang_cc1 -triple mipsisa64r6-linux-gnu -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-64EB // RUN: %clang_cc1 -triple mipsisa64r6-linux-gnuabi64 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-64EB // MIPS-64EB: target datalayout = "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128" // RUN: %clang_cc1 -triple mips64-linux-gnu -o - -emit-llvm %s -target-abi n32 \ // RUN: | FileCheck %s -check-prefix=MIPS-64EB-N32 // RUN: %clang_cc1 -triple mips64-linux-gnuabin32 -o - -emit-llvm %s \ // RUN: | FileCheck %s -check-prefix=MIPS-64EB-N32 // RUN: %clang_cc1 -triple mipsisa64r6-linux-gnu -o - -emit-llvm %s -target-abi n32 \ // RUN: | FileCheck %s -check-prefix=MIPS-64EB-N32 // RUN: %clang_cc1 -triple mipsisa64r6-linux-gnuabin32 -o - -emit-llvm %s \ // RUN: | FileCheck %s -check-prefix=MIPS-64EB-N32 // MIPS-64EB-N32: target datalayout = "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32:64-S128" // RUN: %clang_cc1 -triple powerpc64-lv2 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=PS3 // PS3: target datalayout = "E-m:e-p:32:32-i64:64-n32:64" // RUN: %clang_cc1 -triple i686-nacl -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=I686-NACL // I686-NACL: target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-n8:16:32-S128" // RUN: %clang_cc1 -triple x86_64-nacl -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=X86_64-NACL // X86_64-NACL: target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-n8:16:32:64-S128" // RUN: %clang_cc1 -triple arm-nacl -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=ARM-NACL // ARM-NACL: target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S128" // RUN: %clang_cc1 -triple mipsel-nacl -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MIPS-NACL // MIPS-NACL: target datalayout = "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64" // RUN: %clang_cc1 -triple wasm32-unknown-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=WEBASSEMBLY32 // WEBASSEMBLY32: target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1" // RUN: %clang_cc1 -triple wasm64-unknown-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=WEBASSEMBLY64 // WEBASSEMBLY64: target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1" // RUN: %clang_cc1 -triple lanai-unknown-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=LANAI // LANAI: target datalayout = "E-m:e-p:32:32-i64:64-a:0:32-n32-S64" // RUN: %clang_cc1 -triple powerpc-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=PPC // PPC: target datalayout = "E-m:e-p:32:32-i64:64-n32" // RUN: %clang_cc1 -triple powerpcle-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=PPCLE // PPCLE: target datalayout = "e-m:e-p:32:32-i64:64-n32" // RUN: %clang_cc1 -triple powerpc64-freebsd -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=PPC64-FREEBSD // PPC64-FREEBSD: target datalayout = "E-m:e-i64:64-n32:64" // RUN: %clang_cc1 -triple powerpc64le-freebsd -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=PPC64LE-FREEBSD // PPC64LE-FREEBSD: target datalayout = "e-m:e-i64:64-n32:64" // RUN: %clang_cc1 -triple powerpc64-linux -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=PPC64-LINUX // PPC64-LINUX: target datalayout = "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512" // RUN: %clang_cc1 -triple powerpc64-linux -o - -emit-llvm -target-cpu future %s | \ // RUN: FileCheck %s -check-prefix=PPC64-FUTURE // PPC64-FUTURE: target datalayout = "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512" // RUN: %clang_cc1 -triple powerpc64-linux -o - -emit-llvm -target-cpu pwr10 %s | \ // RUN: FileCheck %s -check-prefix=PPC64-P10 // PPC64-P10: target datalayout = "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512" // RUN: %clang_cc1 -triple powerpc64le-linux -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=PPC64LE-LINUX // PPC64LE-LINUX: target datalayout = "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512" // RUN: %clang_cc1 -triple powerpc64le-linux -o - -emit-llvm -target-cpu future %s | \ // RUN: FileCheck %s -check-prefix=PPC64LE-FUTURE // PPC64LE-FUTURE: target datalayout = "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512" // RUN: %clang_cc1 -triple powerpc64le-linux -o - -emit-llvm -target-cpu pwr10 %s | \ // RUN: FileCheck %s -check-prefix=PPC64LE-P10 // PPC64LE-P10: target datalayout = "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512" // RUN: %clang_cc1 -triple nvptx-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=NVPTX // NVPTX: target datalayout = "e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64" // RUN: %clang_cc1 -triple nvptx64-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=NVPTX64 // NVPTX64: target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64" // RUN: %clang_cc1 -triple r600-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=R600 // R600: target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1" // RUN: %clang_cc1 -triple r600-unknown -target-cpu cayman -o - -emit-llvm %s \ // RUN: | FileCheck %s -check-prefix=R600D // R600D: target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1" // RUN: %clang_cc1 -triple amdgcn-unknown -target-cpu hawaii -o - -emit-llvm %s \ // RUN: | FileCheck %s -check-prefix=R600SI // R600SI: target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7" // Test default -target-cpu // RUN: %clang_cc1 -triple amdgcn-unknown -o - -emit-llvm %s \ // RUN: | FileCheck %s -check-prefix=R600SIDefault // R600SIDefault: target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7" // RUN: %clang_cc1 -triple arm64-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=AARCH64 // AARCH64: target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" // RUN: %clang_cc1 -triple arm64_32-apple-ios7.0 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=AARCH64-ILP32 // AARCH64-ILP32: target datalayout = "e-m:o-p:32:32-i64:64-i128:128-n32:64-S128" // RUN: %clang_cc1 -triple arm64-pc-win32-macho -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=AARCH64-WIN32-MACHO // AARCH64-WIN32-MACHO: target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" // RUN: %clang_cc1 -triple thumb-unknown-gnueabi -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=THUMB // THUMB: target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" // RUN: %clang_cc1 -triple arm-unknown-gnueabi -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=ARM // ARM: target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" // RUN: %clang_cc1 -triple thumb-unknown -o - -emit-llvm -target-abi apcs-gnu \ // RUN: %s | FileCheck %s -check-prefix=THUMB-GNU // THUMB-GNU: target datalayout = "e-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32" // RUN: %clang_cc1 -triple arm-unknown -o - -emit-llvm -target-abi apcs-gnu \ // RUN: %s | FileCheck %s -check-prefix=ARM-GNU // ARM-GNU: target datalayout = "e-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32" // RUN: %clang_cc1 -triple arc-unknown-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=ARC // ARC: target datalayout = "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-f32:32:32-i64:32-f64:32-a:0:32-n32" // RUN: %clang_cc1 -triple hexagon-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=HEXAGON // HEXAGON: target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048" // RUN: %clang_cc1 -triple s390x-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z10 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ // RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch8 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z196 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ // RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch9 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ // RUN: %clang_cc1 -triple s390x-unknown -target-cpu zEC12 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ // RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch10 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z13 -target-feature +soft-float -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ // SYSTEMZ: target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64" // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z13 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR // RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch11 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z14 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR // RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch12 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z15 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR // RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch13 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR // SYSTEMZ-VECTOR: target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64" // RUN: %clang_cc1 -triple msp430-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MSP430 // MSP430: target datalayout = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16" // RUN: %clang_cc1 -triple tce-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=TCE // TCE: target datalayout = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32-v128:32:32-v256:32:32-v512:32:32-v1024:32:32-a0:0:32-n32" // RUN: %clang_cc1 -triple tcele-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=TCELE // TCELE: target datalayout = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32-v128:32:32-v256:32:32-v512:32:32-v1024:32:32-a0:0:32-n32" // RUN: %clang_cc1 -triple spir-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SPIR // SPIR: target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" // RUN: %clang_cc1 -triple spir64-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SPIR64 // SPIR64: target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" // RUN: %clang_cc1 -triple bpfel -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=BPFEL // BPFEL: target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128" // RUN: %clang_cc1 -triple bpfeb -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=BPFEB // BPFEB: target datalayout = "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128" // RUN: %clang_cc1 -triple ve -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=VE // VE: target datalayout = "e-m:e-i64:64-n32:64-S128-v64:64:64-v128:64:64-v256:64:64-v512:64:64-v1024:64:64-v2048:64:64-v4096:64:64-v8192:64:64-v16384:64:64"
the_stack_data/74047.c
#include<stdio.h> int main() { int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat; printf("Enter Total Number of Process:"); scanf("%d",&n); printf("\nEnter Burst Time and Priority\n"); for(i=0;i<n;i++) { printf("\nP[%d]\n",i+1); printf("Burst Time:"); scanf("%d",&bt[i]); printf("Priority:"); scanf("%d",&pr[i]); p[i]=i+1; //contains process number } //sorting burst time, priority and process number in ascending order using selection sort for(i=0;i<n;i++) { pos=i; for(j=i+1;j<n;j++) { if(pr[j]<pr[pos]) pos=j; } temp=pr[i]; pr[i]=pr[pos]; pr[pos]=temp; temp=bt[i]; bt[i]=bt[pos]; bt[pos]=temp; temp=p[i]; p[i]=p[pos]; p[pos]=temp; } wt[0]=0; //waiting time for first process is zero //calculate waiting time for(i=1;i<n;i++) { wt[i]=0; for(j=0;j<i;j++) wt[i]+=bt[j]; total+=wt[i]; } avg_wt=total/n; //average waiting time total=0; printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time"); for(i=0;i<n;i++) { tat[i]=bt[i]+wt[i]; //calculate turnaround time total+=tat[i]; printf("\nP[%d]\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]); } avg_tat=total/n; //average turnaround time printf("\n\nAverage Waiting Time=%d",avg_wt); printf("\nAverage Turnaround Time=%d\n",avg_tat); return 0; }
the_stack_data/179830102.c
#include <stdio.h> #include <locale.h> void main() { double* m, ** k, myArray[5] = { 1.0,2.0,3.0,4.0,5.0 }; m = myArray; //m=&myArray[0] m dizinin ilk elemanın adresidir. printf("%.1f\n", *(m + 1)); // Output=2.0 *(m + 3) += 3.86; // myArray[3]= *(m+3) =7.86 m += 2; // m artık dizi[2] de başlıyor. printf("%.1f\n", *(m + 1)); //Output=7.9 m = &myArray[3]; //m artık MyArray[3] adresini tutuyor. k = &m; printf("%.1f\n", *(*(k)-1)); //myArray[2] değerini verir. printf("%p\n", *k); //myArray[3]'ün adresini verir. m = m - 1; printf("%p", m); //myArray[2] adresini verir. }
the_stack_data/839962.c
#include <stdio.h> #include <stdlib.h> int main() { int semestre, disciplinas, cont, cont2, cont3, carga_horaria, horas_cumpridas, qtd_notas; int aprovN = 0, reproN = 0, qtdis = 0, reproF = 0, reproA = 0; double notastotal, medianotas, notas, frequencia; double ida = 0; double soma_notas_aprova = 0; printf("Quantos semestres: "); scanf("%i", &semestre); for(cont = 1; cont <= semestre; cont++) { int SaprovN = 0, SreproN = 0, SreproF = 0, SreproA = 0; double Sida = 0; double Ssoma_notas_aprova = 0; printf("Semestre %i\n", cont); printf("Quantas disciplinas: "); scanf("%i", &disciplinas); qtdis += disciplinas; for(cont2 = 1; cont2 <= disciplinas; cont2++) { printf("Disciplinas: %i\n", cont2); printf("\nCarga horaria: "); scanf("%i", &carga_horaria); printf("\nHoras cumpridas: "); scanf("%i", &horas_cumpridas); if(horas_cumpridas > carga_horaria) { return 0; } printf("\nQuantidades de notas: "); scanf("%i", &qtd_notas); for(cont3 = 1; cont3 <= qtd_notas ; cont3++) { printf("Notas: \n"); scanf("%lf", &notas); if(notas < 0 || notas > 10) { return 0; } notastotal = notastotal + notas; if(cont3 == qtd_notas) { medianotas = notastotal / qtd_notas; printf("sua media das disciplinas: %.2lf\n", medianotas); notastotal = 0; frequencia = horas_cumpridas * 100 / carga_horaria; if(medianotas > 7 && frequencia > 75){ printf("\n-Aprovado!\n\n"); aprovN++; SaprovN++; Sida += medianotas * carga_horaria; Ssoma_notas_aprova += medianotas; } else if(medianotas > 7 && frequencia < 75){ printf("\n-Reprovado por frequencia!\n\n"); reproF++; SreproF++; Sida -= (7.0 - medianotas) * carga_horaria; } else if(medianotas < 7 && frequencia > 75){ printf("\n-Reprovado por nota!\n\n"); reproN++; SreproN++; Sida -= (7.0 - medianotas) * carga_horaria; } else if(medianotas <7 && frequencia <75){ printf("\n-Reprovado!\n\n!"); reproA++; SreproA++; Sida -= (7.0 - medianotas) * carga_horaria; } } } } printf("=========Relatorio do Semestre=============\n"); printf("Aprovadas:%i \n Reprovadas:%i \n Reprovadas por nota: %i\n Reprovas por Frequecia: %i\n Aprovadas em %.2lf%% das disciplinas do semestre\n", SaprovN, SreproN+SreproF, SreproN, SreproF, SaprovN * 100.0 / (double)disciplinas); printf("IDA: %.2lf\n", Sida); if (SaprovN > 0) printf("MGA: %.2lf\n", Ssoma_notas_aprova / SaprovN); else printf("MGA indefinido\n"); ida += Sida; soma_notas_aprova += Ssoma_notas_aprova; } printf("=========Relatorio Final=============\n"); printf("Quantidade de disciplinas:%i \n", qtdis); printf("Aprovadas:%i \n Reprovadas:%i \n Reprovadas por nota: %i\n Reprovas por Frequecia: %i\n", aprovN, reproN+reproF, reproN, reproF); printf("IDA: %.2lf\n", ida); if (aprovN > 0) printf("MGA: %.2lf\n", soma_notas_aprova / aprovN); else printf("MGA indefinido\n"); return 0; }
the_stack_data/67325790.c
int main() { int i=0, x=0, y=0; int n=rand(); assume(n>0); for(i=0; 1; i++) { assert(x==0); } assert(x!=0); }
the_stack_data/117328699.c
// RUN: %clang_cc1 -fmath-errno -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s --check-prefix=HAS_ERRNO // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s --check-prefix=NO_ERRNO float foo(float X) { // HAS_ERRNO: call float @sqrtf(float // NO_ERRNO: call float @llvm.sqrt.f32(float return __builtin_sqrtf(X); } // HAS_ERRNO: declare float @sqrtf(float noundef) [[ATTR:#[0-9]+]] // HAS_ERRNO-NOT: attributes [[ATTR]] = {{{.*}} readnone // NO_ERRNO: declare float @llvm.sqrt.f32(float) [[ATTR:#[0-9]+]] // NO_ERRNO: attributes [[ATTR]] = { nofree nosync nounwind readnone {{.*}}}
the_stack_data/145074.c
#include <math.h> #define MAXIT 100 #define EPS 3.0e-7 #define FPMIN 1.0e-30 float betacf(float a, float b, float x) { void nrerror(char error_text[]); int m,m2; float aa,c,d,del,h,qab,qam,qap; qab=a+b; qap=a+1.0; qam=a-1.0; c=1.0; d=1.0-qab*x/qap; if (fabs(d) < FPMIN) d=FPMIN; d=1.0/d; h=d; for (m=1;m<=MAXIT;m++) { m2=2*m; aa=m*(b-m)*x/((qam+m2)*(a+m2)); d=1.0+aa*d; if (fabs(d) < FPMIN) d=FPMIN; c=1.0+aa/c; if (fabs(c) < FPMIN) c=FPMIN; d=1.0/d; h *= d*c; aa = -(a+m)*(qab+m)*x/((a+m2)*(qap+m2)); d=1.0+aa*d; if (fabs(d) < FPMIN) d=FPMIN; c=1.0+aa/c; if (fabs(c) < FPMIN) c=FPMIN; d=1.0/d; del=d*c; h *= del; if (fabs(del-1.0) < EPS) break; } if (m > MAXIT) nrerror("a or b too big, or MAXIT too small in betacf"); return h; } #undef MAXIT #undef EPS #undef FPMIN
the_stack_data/305226.c
#include <stdio.h> /* HOWTO in Debian (stretch-slim): 1) install gcc as 'apt-get install --no-install-recommends gcc libc6-dev' 2) compile it as 'gcc hello.c -o hello' 3) run it as './hello' */ int main() { puts("Hello there from Debian!"); return 0; }
the_stack_data/165769026.c
#include<stdio.h> #include<stdlib.h> #include<unistd.h> int main() { char *args[]={"./exec.out",NULL}; printf("Before Handing Over.\n"); execv(args[0],args); printf("After Handing Over.\n"); printf("Done"); }
the_stack_data/67324418.c
#ifdef HAVE_STARKWARE #include "shared_context.h" #include "stark_utils.h" #include "ui_callbacks.h" unsigned int io_seproxyhal_touch_stark_ok(const bagl_element_t *e) { uint8_t privateKeyData[32]; uint8_t signature[72]; uint32_t tx = 0; io_seproxyhal_io_heartbeat(); starkDerivePrivateKey(tmpCtx.transactionContext.bip32Path, tmpCtx.transactionContext.pathLength, privateKeyData); io_seproxyhal_io_heartbeat(); stark_sign(signature, privateKeyData, dataContext.starkContext.w1, dataContext.starkContext.w2, dataContext.starkContext.w3); G_io_apdu_buffer[0] = 0; format_signature_out(signature); tx = 65; G_io_apdu_buffer[tx++] = 0x90; G_io_apdu_buffer[tx++] = 0x00; reset_app_context(); // Send back the response, do not restart the event loop io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); // Display back the original UX ui_idle(); return 0; // do not redraw the widget } #endif
the_stack_data/851320.c
#include<stdio.h> #include<string.h> int main(){ char word[100]; int i=0; int hashtable[26]; int k=0; scanf("%s",word); int length = strlen(word); for(i=0;i<26;i++) hashtable[i]=0; for(i=0;i<length;i++){ int temp = ((int)word[i]-97); hashtable[temp]++; if(hashtable[temp] >= 2){ printf("%c",temp+97); } } return 0; }
the_stack_data/264811.c
#include <stdio.h> int getfibo(int n){ if(n==0){ return 0; } else if(n ==1){ return 1; } else { return (getfibo(n-1) + getfibo(n-2)); } } int main(){ int n = 20; printf("Fibbonacci sereis of %d: " , n); for(int i = 0;i<n;i++) { printf("%d ",getfibo(i)); } printf("\n"); /* iterative version int a = 0; int b = 1; int c = a +b; printf("%i-%i",a,b); for (int i = 0; i < 10; i++) { printf("-%i",c); a = b; b = c; c = a+b; } printf("\n"); */ return 0; } //readmore -> https://visualgo.net/en/recursion
the_stack_data/445829.c
/* * 快速排序来给数组排序 */ #include <stdio.h> int findpos(int arr[], int first, int last); void quicksort(int arr[], int begin, int end); int main() { int arr[] = {73, 108, 11, 118, 101, 70, 105, 115, 104, 67, 46, 99, 111, 109}; int length = sizeof(arr)/sizeof(arr[0]); quicksort(arr, 0, length - 1); for(int i = 0; i < length; i++){ printf("%d ", arr[i]); } printf("\n"); return 0; } void quicksort(int arr[], int begin, int end) { int pos; if(begin < end){ pos = findpos(arr, begin, end); quicksort(arr, begin, pos - 1); quicksort(arr, pos + 1, end); } } int findpos(int arr[], int first, int last) { int tmp = arr[first]; while(first < last){ while(first < last && arr[last] >= tmp){ last--; } arr[first] = arr[last]; while(arr[first] <= tmp && first < last){ first++; } arr[last] = arr[first]; } arr[last] = tmp; return last; }
the_stack_data/26700062.c
extern void abort (void); typedef short fract16; int main () { fract16 t1; t1 = __builtin_bfin_max_fr1x16 (0x8000, 0xc000); if (t1 != -0x4000) abort (); return 0; }
the_stack_data/237642899.c
#include <sys/mman.h> #include <unistd.h> #include <string.h> #include <stdio.h> typedef int (*pfun_add)(int*); unsigned char *ucfun_add="\x55\x48\x89\xe5\x48\x89\x7d\xf8\x48\x8b\x45\xf8\x8b\x00\x8d\x50\x01\x48\x8b\x45\xf8\x89\x10\xb8\x00\x00\x00\x00\x5d\xc3"; pfun_add init_fun_add() { size_t szfun_add=37; pfun_add pf=(pfun_add)mmap(NULL, szfun_add, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_SHARED, -1, 0); memcpy(pf,ucfun_add,szfun_add); return pf; } // Modify the typedef line above to match your dumped function. // An example of calling the binary function. //------------------------- // pfun_add fun_add=init_fun_add(); // fun_add(); //------------------------- // int main(){ int a=0; pfun_add fun_add=init_fun_add(); printf("a=%d\n",a); fun_add(&a); printf("a=%d\n",a); return 0; }
the_stack_data/153269197.c
/* * sbitget -- extract bitmap-data from a TrueType font * version 0.1 * Mon Jan 30 2002 * Itou Hiroki */ /* * Copyright (c) 2002 ITOU Hiroki * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #define PROGNAME "sbitget" #define PROGVERSION "0.1" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> /* stat() */ #include <stdarg.h> /* vfprintf() */ #include <unistd.h> #define uchar unsigned char #define ulong unsigned long #define ushort unsigned short #define BUFSIZE 64 #define GLYPHBUFSIZE 1000 #define MAXGLYPHWIDTH 128 #define TMPFILE "sbit.tmp" #define MAXFILENAMECHAR 256 #define MAXSTRINGINBDF 1000 #define LEVELCOPYRIGHTSTR 4 #define LEVELFONTNAMESTR 8 #define STRUNKNOWN "???" //info of tables typedef struct linkedlist_tag{ struct linkedlist_tag *next; //next element's on-memory location ulong offset; //(byte) offset from top of TrueTypeFile to top of this table // ulong len; //(byte) length of this table char tag[5]; //name of this table (4 characters + '\0') } tableinfo; //info of glyph-metric (metric means size) typedef struct { uchar width; uchar height; ulong off; //offset from top of EBDT to top of glyph data uchar advance; // same as DWIDTH(BDF) int offsetx; //offset of boundingbox from origin to point of //most right-under. // that is, the axis of most right-under int offsety; uchar ppem; //pixel-size in this strike uchar *ebdtL; //on-memory location: top of EBDT int imageFormat; ushort id; //glyph ID number (index number) } metricinfo; typedef struct { uchar *subtableL; //location top of indexSubTable (in EBLC) ushort first; //firstGlyphIndex ushort last; //lastGlyphIndex int indexFormat; ulong off; //imageDataOffset from EBDTtop to locationOfGlyphsData } indexSubTable_info; typedef struct { uchar *strL; ushort slen; } str_info; /* func prototype */ int main(int argc, char **argv); void see_eblc(uchar *eblcL, uchar *ebdtL, char *copyright, char *fontname); ushort see_indexSubTable(indexSubTable_info *st, uchar *ebdtL, FILE *outfp); void getTableInfo(uchar *p, tableinfo *t); void validiateTTF(uchar *p); uchar *mread(uchar *p, int size, char *s); void see_bitmapSizeTable(uchar *p, int *numElem, ulong *arrayOffset, metricinfo *bbox); uchar *see_sbitLineMetrics(uchar *p, metricinfo *bbox, int direction); void see_indexSubTableArray(uchar *elemL, uchar *arrayL, indexSubTable_info *st); int see_indexSubHeader(indexSubTable_info *st); void putglyph(metricinfo *glyph, int size, FILE *outfp); void setGlyphHead(metricinfo *g, char *s); void setGlyphBody_byte(uchar *p, const uchar *end, metricinfo *g, char *s); void setGlyphBody_bit(uchar *p, const uchar *end, metricinfo *g, char *s); void errexit(char *fmt, ...); uchar *see_glyphMetrics(uchar *p, metricinfo *met, int big); void see_name(uchar *nameL, char *copyright, char *fontname); void copystr(char *dst, uchar *src, ushort len, int forFilename); /* * reading a TrueType font * calling functions for 'name', 'EBLC', 'EBDT' tables */ int main(int argc, char **argv){ uchar *ttfL; //on memory location: top of TrueTypeFile char copyright[MAXSTRINGINBDF] = STRUNKNOWN; char fontname[MAXSTRINGINBDF] = STRUNKNOWN; if(argc!=2){ fprintf(stderr, PROGNAME " version " PROGVERSION " - extract bitmap-data from a TrueType font\n"); fprintf(stderr, "usage: " PROGNAME " file.ttf\n"); exit(1); } /* * reading TrueTypeFile to Memory */ { FILE *fp; size_t ttfsize; struct stat info; if((fp=fopen(argv[1],"rb"))==NULL) errexit("cannot open '%s'", argv[1]); if(stat(argv[1], &info) != 0) errexit("stat"); ttfsize = info.st_size; if((ttfL=malloc(ttfsize))==NULL) errexit("malloc"); if(fread(ttfL, 1, ttfsize, fp)!=ttfsize) errexit("fread"); fclose(fp); } //ckeck this file is TrueType? or not validiateTTF(ttfL); { tableinfo table; //store the first table //dynamically allocate second and after tables tableinfo *t; //loop uchar *eblcL = NULL; //on memory location: top of EBLC table uchar *ebdtL = NULL; //on memory location: top of EBDT table //get locations of tables getTableInfo(ttfL, &table); /* * reading name table * get strings of copyright, fontname */ for(t=table.next; t->next!=NULL; t=t->next){ if(strcmp("name", t->tag)==0){ see_name(ttfL + t->offset, copyright, fontname); break; } } //EBDT table for(t=table.next; t->next!=NULL; t=t->next){ if(strcmp("EBDT", t->tag)==0 || strcmp("bdat", t->tag)==0) ebdtL = ttfL + t->offset; } if(ebdtL == NULL) errexit("This font has no bitmap-data."); // EBLC table for(t=table.next; t->next!=NULL; t=t->next){ if(strcmp("EBLC", t->tag)==0 || strcmp("bloc", t->tag)==0) eblcL = ttfL + t->offset; } if(eblcL == NULL) errexit("This font has no bitmap-data."); see_eblc(eblcL, ebdtL, copyright, fontname); } exit(EXIT_SUCCESS); } /* * reading EBLC table * in: on-memory location: top of EBLC * on-memory location: top of EBDT * strings of copyright * strings of fontname * out: nothing */ void see_eblc(uchar *eblcL, uchar *ebdtL, char *copyright, char *fontname){ char s[BUFSIZE]; int numSize; //number of BitmapSizeTable int i,j; /* * reading EBLC header * get number of bitmapSizeTable */ { uchar *p = eblcL; //version number p = mread(p, sizeof(ulong), s); //number of bitmapSizeTable p = mread(p, sizeof(ulong), s); numSize = (ulong)strtol(s,(char**)NULL,16); } /* * reading bitmapSizeTables */ for(i=0; i<numSize; i++){ uchar *arrayL; //on-memory location: top of indexSubTableArray int numElem; //number of indexSubTableArray-elements metricinfo bbox; //strike's bounding box: metric info for strike FILE *outfp; ushort totalglyphs; //this program can handle under 65536 glyphs /* * reading a bitmapSizeTable * get number of indexSubTableArrays * get location of a first indexSubTableArray * get info of BoundingBox */ { ulong offset; //from EBLCtop to a first indexSubTableArray //8 = size of EBLCheader, 48 = size of one bitmapSizeTable see_bitmapSizeTable(eblcL+8+(48*i), &numElem, &offset, &bbox); arrayL = eblcL + offset; } /* * prepare to write a tmp file */ if((outfp=fopen(TMPFILE,"wb"))==NULL) errexit("fopen"); totalglyphs = 0; /* * reading indexSubTableArrays and indexSubTables */ for(j=0; j<numElem; j++){ indexSubTable_info st; /* * reading an indexSubTableArray * get firstGlyphIndex, lastGlyphIndex * get location of indexSubTable */ //8 = size of one indexSubTableArray see_indexSubTableArray(arrayL+(j*8), arrayL, &st); /* * reading indexSubTable * get info of glyphs... read bitmapdata... write to tmpfile... */ totalglyphs += see_indexSubTable(&st, ebdtL, outfp); } /* * write to a tmp file */ if(fclose(outfp)!=0) errexit("fclose"); /* * add some to the tmp file, and write a bdf file */ { FILE *infp; char *filebuf; struct stat info; char fname[MAXFILENAMECHAR]; if(strcmp(fontname,STRUNKNOWN)==0) sprintf(fname, "sbit-%02dpx.bdf", bbox.ppem); else sprintf(fname, "%s-%02dpx.bdf", fontname, bbox.ppem); if((outfp=fopen(fname,"wb"))==NULL) errexit("fopen"); //read that tmp file if((infp=fopen(TMPFILE,"rb"))==NULL) errexit("fopen"); if(stat(TMPFILE, &info) != 0) errexit("stat"); if((filebuf=calloc(info.st_size, sizeof(char)))==NULL) errexit("calloc"); if(fread(filebuf,1,info.st_size,infp)!=info.st_size) errexit("fread"); fprintf(outfp, "STARTFONT 2.1\n" "COMMENT extracted with %s %s\n" "FONT %s\n" "SIZE %d 75 75\n" "FONTBOUNDINGBOX %d %d %d %d\n" "STARTPROPERTIES 1\n" "COPYRIGHT \"%s\"\n" "ENDPROPERTIES\n" "CHARS %d\n" ,PROGNAME, PROGVERSION ,fontname ,bbox.ppem ,bbox.width, bbox.height, bbox.offsetx, bbox.offsety ,copyright ,totalglyphs); if(fwrite(filebuf,1,info.st_size,outfp)!=info.st_size) errexit("fwrite"); fprintf(outfp, "ENDFONT\n"); fclose(outfp); fprintf(stderr, " wrote '%s'\n", fname); //remove tmp file fclose(infp); if(remove(TMPFILE)!=0) errexit("remove"); } } } /* * reading indexSubTable * in: info of indexSubTable * out: number of glyphs contained in this indexSubTable */ ushort see_indexSubTable(indexSubTable_info *st, uchar *ebdtL, FILE *outfp){ metricinfo glyph; int i; char s[BUFSIZE]; uchar *p; ushort numGlyphs = 0; /* * reading the header of indexSubTable * get indexFormat (order of glyphs in EBDT) * get imageFormat (type of image format of glyphs in EBDT) * get offset from EBDTtop to locationOfGlyphsData */ glyph.imageFormat = see_indexSubHeader(st); p = st->subtableL + 8; //8 = size of indexSubHeader glyph.ebdtL = ebdtL; /* * reading the body of indexSubTable */ switch (st->indexFormat){ case 1: // proportional with 4byte offset { ulong nextoff, curoff; //next glyph's offset, current offset // to know last glyph's length, +1 is needed for(i=st->first; i<= st->last + 1; i++){ p = mread(p, sizeof(ulong), s); nextoff = (ulong)strtol(s,(char**)NULL,16); if(i!=st->first && nextoff-curoff>0){ glyph.off = st->off + curoff; glyph.id = i-1; putglyph(&glyph, nextoff-curoff, outfp); numGlyphs++; } curoff = nextoff; } } break; case 3: //proportional with 2byte offset { ushort nextoff, curoff; for(i=st->first; i<= st->last + 1; i++){ p = mread(p, sizeof(ushort), s); nextoff = (ushort)strtol(s,(char**)NULL,16); if(i!=st->first && nextoff-curoff>0){ glyph.off = st->off + curoff; glyph.id = i-1; putglyph(&glyph, nextoff-curoff, outfp); numGlyphs++; } curoff = nextoff; } } break; case 4: // proportional with sparse codes { ulong nGlyphs; ushort nextoff, curoff, nextid, curid; //current ID, nextID p = mread(p, sizeof(ulong), s); nGlyphs = (ulong)strtol(s,(char**)NULL,16); for(i=0; i<nGlyphs+1; i++){ p = mread(p, sizeof(ushort), s); nextid = (ushort)strtol(s,(char**)NULL,16); p = mread(p, sizeof(ushort), s); nextoff = (ushort)strtol(s,(char**)NULL,16); if(i!=0 && nextoff-curoff>0){ glyph.off = st->off + curoff; glyph.id = curid; putglyph(&glyph, nextoff-curoff, outfp); numGlyphs++; } curoff = nextoff; curid = nextid; } } break; case 2: //monospaced with close codes { ulong imageSize; p = mread(p, sizeof(ulong), s); imageSize = (ulong)strtol(s,(char**)NULL,16); p = see_glyphMetrics(p, &glyph, 1); for(i=st->first; i<=st->last; i++){ glyph.off = st->off + imageSize * (i - st->first); glyph.id = i; putglyph(&glyph, imageSize, outfp); numGlyphs++; } } break; case 5: //monospaced with sparse codes { ulong imageSize, nGlyphs; p = mread(p, sizeof(ulong), s); imageSize = (ulong)strtol(s,(char**)NULL,16); p = see_glyphMetrics(p, &glyph, 1); p = mread(p, sizeof(ulong), s); nGlyphs = (ulong)strtol(s,(char**)NULL,16); for(i=0; i<nGlyphs; i++){ p = mread(p, sizeof(ushort), s); glyph.id = (ushort)strtol(s,(char**)NULL,16); glyph.off = st->off + imageSize * i; putglyph(&glyph, imageSize, outfp); numGlyphs++; } } break; default: errexit("indexFormat %d is not supported.", st->indexFormat); break; } //skip padding for(i=0; i<(p - st->subtableL)%4; i++) p = mread(p, sizeof(uchar), s); return numGlyphs; } /* * reading TrueTypefont header * in: on-memory top of truetype font * (for out) info of each table * out: nothing */ void getTableInfo(uchar *p, tableinfo *t){ int i; ushort numTable; char s[BUFSIZE]; p = mread(p, sizeof(ulong), s); //version p = mread(p, sizeof(ushort), s); //number of tables numTable = (ushort)strtol(s,(char**)NULL,16); p = mread(p, sizeof(ushort), s); //searchRange p = mread(p, sizeof(ushort), s); //entrySelector p = mread(p, sizeof(ushort), s); //rangeShift /* * assign info of table */ for(i=0; i<numTable; i++){ //allocate for a tableinfo (free() don't exist) if( (t->next=malloc(sizeof(tableinfo))) == NULL) errexit("malloc"); t = t->next; //a name of table (tag) memset(t->tag, 0x00, 5); // 0 clear memcpy(t->tag, p, 4); p += sizeof(ulong); p += sizeof(ulong); //checksum (not use now) //offset p = mread(p, sizeof(ulong), s); //number of tables t->offset = (ulong)strtol(s,(char**)NULL,16); p += sizeof(ulong); //length (not use now) } t->next = NULL; } /* * checking TrueTypefont or not * in: on-memory location: top of truetype font * out: nothing * * If errors, exit program. */ void validiateTTF(uchar *p){ char s[BUFSIZE]; p = mread(p, sizeof(ulong), s); //version if(strcmp(s,"0x00010000")==0){ printf(" Microsoft TrueType/OpenType\n"); }else if(strcmp(s, "0x74746366")==0){ printf(" Microsoft TrueTypeCollection\n"); errexit("TTC file is not supported yet."); }else if(strcmp(s, "0x74727565")==0){ printf(" Apple TrueType\n"); }else{ errexit("This file is not a TrueTypeFont."); } } /* * reading given bytes, return to string & pointer * in: on-memory location to read * byte size to read * (for out) string pointer to assign * out: on-memory location to read next */ uchar *mread(uchar *p, int size, char *s){ int i; memset(s, 0x00, BUFSIZE); //zero clear sprintf(s, "0x"); //add '0x' for make indentified as hexadecimal for(i=0; i<size; i++){ sprintf(s+(i*2)+2, "%02x", *p); p++; } return p; } /* * reading bitmapSizeTable(defines info of strike) in EBLC * in: on-memory location: top of a bitmapSizeTable * (for out) number of indexSubTableArray-elements * (for out) on-memory location: top of indexSubTableArray * (for out) info of BoundingBox * out: nothing */ void see_bitmapSizeTable(uchar *p, int *numElem, ulong *arrayOffset, metricinfo *bbox){ char s[BUFSIZE]; //stored string //offset from EBLCtop to indexSubTableArray p = mread(p, sizeof(ulong), s); *arrayOffset = (ulong)strtol(s,(char**)NULL,16); //indexSubTable size (byte) (not use) p = mread(p, sizeof(ulong), s); //number of indexSubTableArray-elements (= number of indexSubTables) p = mread(p, sizeof(ulong), s); *numElem = (ulong)strtol(s,(char**)NULL,16); //colorRef (always 0) p = mread(p, sizeof(ulong), s); //sbitLineMetrics: hori //info of metric about all glyphs in a strike p = see_sbitLineMetrics(p, bbox, 1); // 1 means direction==horizontal //sbitLineMetrics: vert (not use) p = see_sbitLineMetrics(p, NULL, 0); // 0 means direction==vertical //start glyphIndex for this size p = mread(p, sizeof(ushort), s); //end glyphIndex for this size p = mread(p, sizeof(ushort), s); //ppemX (the strike's boundingbox width (pixel)) p = mread(p, sizeof(uchar), s); bbox->ppem = (uchar)strtol(s,(char**)NULL,16); //ppemY p = mread(p, sizeof(uchar), s); //bitDepth (always 1) p = mread(p, sizeof(uchar), s); //flags (1=horizontal, 2=vertical) p = mread(p, sizeof(char), s); return; } /* * reading info of metric * in: on-memory location: top of metric-info * directionHori: 1=horizontal, 0=vertical * out: on-memory location: just after metric-info */ uchar *see_sbitLineMetrics(uchar *p, metricinfo *bbox, int directionHori){ char s[BUFSIZE]; char widthMax, maxBeforeBL, minAfterBL, minOriginSB; //ascender: distance from baseline to upper-line (px) p = mread(p, sizeof(char), s); //descender: distance from baseline to bottom-line (px) p = mread(p, sizeof(char), s); //widthMax p = mread(p, sizeof(uchar), s); widthMax = (char)strtol(s,(char**)NULL,16); //caratSlopeNumerator p = mread(p, sizeof(char), s); //caratSlopeDenominator p = mread(p, sizeof(char), s); //caratOffset p = mread(p, sizeof(char), s); //minOriginSB p = mread(p, sizeof(char), s); minOriginSB = (char)strtol(s,(char**)NULL,16); //minAdvanceSB p = mread(p, sizeof(char), s); //maxBeforeBL p = mread(p, sizeof(char), s); maxBeforeBL = (char)strtol(s,(char**)NULL,16); //minAfterBL p = mread(p, sizeof(char), s); minAfterBL = (char)strtol(s,(char**)NULL,16); //pad1 p = mread(p, sizeof(char), s); //pad2 p = mread(p, sizeof(char), s); //if direction==hori, assign metric-info //elseif direction==vert, don't assign if(directionHori){ bbox->width = widthMax; bbox->height = maxBeforeBL - minAfterBL; bbox->offsetx = minOriginSB; bbox->offsety = minAfterBL; } return p; } /* * reading an indexSubTableArray * in: on-memery location: top of indexSubTableArray-elements * on-memery location: top of indexSubTableArray * (for out) info of indexSubTable * out: nothing */ void see_indexSubTableArray(uchar *elemL, uchar *arrayL, indexSubTable_info *st){ char s[BUFSIZE]; uchar *p = elemL; //firstGlyphIndex p = mread(p, sizeof(ushort), s); st->first = (ushort)strtol(s,(char**)NULL,16); //lastGlyphIndex p = mread(p, sizeof(ushort), s); st->last = (ushort)strtol(s,(char**)NULL,16); //location of indexSubTable p = mread(p, sizeof(ulong), s); st->subtableL = arrayL + (ulong)strtol(s,(char**)NULL,16); } /* * raeding header of an indexSubTable * in: (for in and out) info of indexSubTable * out: imageFormat */ int see_indexSubHeader(indexSubTable_info *st){ char s[BUFSIZE]; char *p = st->subtableL; int imageFormat; //indexFormat p = mread(p, sizeof(ushort), s); st->indexFormat = strtol(s,(char**)NULL,16); //imageFormat p = mread(p, sizeof(ushort), s); imageFormat = (ushort)strtol(s,(char**)NULL,16); //imageDataOffset p = mread(p, sizeof(ulong), s); st->off = (ulong)strtol(s,(char**)NULL,16); return imageFormat; } /* * read one glyph, and put to file * in: info of a glyph (type of EBDT-imageFormat,... ) * size of bitmapdata * writing-file pointer * out: nothing */ void putglyph(metricinfo *glyph, int size, FILE *outfp){ uchar *glyphL = glyph->ebdtL + glyph->off; uchar *p = glyphL; char s[GLYPHBUFSIZE]; memset(s, 0x00, GLYPHBUFSIZE); switch (glyph->imageFormat){ case 1: //EBDT format 1: byte-aligned, small-metric p = see_glyphMetrics(p, glyph, 0); setGlyphHead(glyph, s); setGlyphBody_byte(p, glyphL+size, glyph, s); break; case 2: //EBDT format 2: bit-aligned, small-metric p = see_glyphMetrics(p, glyph, 0); setGlyphHead(glyph, s); setGlyphBody_bit(p, glyphL+size, glyph, s); break; case 5: //EBDT format 5: bit-aligned, EBLC-metric setGlyphHead(glyph, s); setGlyphBody_bit(p, glyphL+size, glyph, s); break; case 6: //EBDT format 6: byte-aligned, big-metric p = see_glyphMetrics(p, glyph, 1); setGlyphHead(glyph, s); setGlyphBody_byte(p, glyphL+size, glyph, s); break; case 7: //EBDT format 7: bit-aligned, big-metric p = see_glyphMetrics(p, glyph, 1); setGlyphHead(glyph, s); setGlyphBody_bit(p, glyphL+size, glyph, s); break; default: errexit("imageFormat %d is not supported.", glyph->imageFormat); break; } fprintf(outfp, "%sENDCHAR\n", s); } /* * set header of a BDF glyph to string * in: info of glyph(glyph's boudingbox) * (for out) string pointer * out: nothing */ void setGlyphHead(metricinfo *g, char *s){ sprintf(s, "STARTCHAR glyphID:%04x\n" "ENCODING %d\n" "DWIDTH %d\n" "BBX %d %d %d %d\n" "BITMAP\n", g->id, -1, g->advance, g->width, g->height, g->offsetx, g->offsety ); } /* * set bitmap of a BDF glyph: byte-aligned * in: on-memory location: beginning of bitmapdata in EBDT * on-memory location: end of bitmapdata in EBDT * info of glyph (width) * (for out) string pointer * out: nothing */ void setGlyphBody_byte(uchar *p, const uchar *end, metricinfo *g, char *s){ int cnt = 0; //counter: print newline or not char str[GLYPHBUFSIZE]; memset(str, 0x00, GLYPHBUFSIZE); while(p < end){ //read one byte, change to 2 characters of hexadecimal sprintf(str, "%x%x", (*p)>>4, (*p)&0x0f); strcat(s, str); //not print '\n' if cnt < glyph.width-(int)1)/8 if( (g->width-(int)1)/8 <= cnt){ strcat(s, "\n"); cnt = 0; }else{ cnt++; } p++; } } /* * set bitmap of a BDF glyph: bit-aligned * in: on-memory location: beginning of bitmapdata in EBDT * on-memory location: end of bitmapdata in EBDT * info of glyph (width, height) * (for out) string pointer * out: nothing */ void setGlyphBody_bit(uchar *p, const uchar *end, metricinfo *g, char *s){ uchar *b, *mem, *binline, pad; int i,j,k; static char *hex2bin[]= { "0000","0001","0010","0011","0100","0101","0110","0111", "1000","1001","1010","1011","1100","1101","1110","1111" }; char str[GLYPHBUFSIZE]; memset(str, 0x00, GLYPHBUFSIZE); /* * write binary number without padding */ mem = malloc(MAXGLYPHWIDTH * MAXGLYPHWIDTH); //width x height memset(mem, '0', MAXGLYPHWIDTH * MAXGLYPHWIDTH); b = mem; while(p < end){ //read one byte, change to 2 characters of hexadecimal memcpy(b, hex2bin[(*p)>>4], 4); b+=4; memcpy(b, hex2bin[(*p)&0x0f], 4); b+=4; p++; } /* * set padding for hori */ binline = malloc(MAXGLYPHWIDTH); memset(binline, '0', MAXGLYPHWIDTH); pad = ((g->width+7)/8*8) - g->width; for(i=0; i<g->height; i++){ for(j=0; j<g->width; j++){ *(binline+j) = *(mem + (i*g->width) + j); } for( ; j<g->width+pad; j++){ *(binline+j) = '0'; } /* * change back to hexadecimal */ for(j=0; j<g->width+pad; j+=4){ for(k=0x0; k<=0xf; k++){ if(strncmp(binline+j,hex2bin[k],4)==0){ sprintf(str, "%x", k); strcat(s, str); } } } strcat(s, "\n"); } free(mem); free(binline); } /* * display error messages, and exit this program * in: variable arguments to print * out: nothing */ void errexit(char *fmt, ...){ va_list ap; va_start(ap, fmt); // fprintf(stderr, "%s: ", PROGNAME); fprintf(stderr, " Error: "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); exit(EXIT_FAILURE); } /* * reading BigGlyphMetrics/SmallGlyphMetrics in EBLC * in: on-memory location: top of Big/Small GlyphMetrics * (for out) info of glyph * Big or Small (1==big, 0==small) * out: on-memory location: just after Big/Small GlyphMetrics */ uchar *see_glyphMetrics(uchar *p, metricinfo *met, int big){ char s[BUFSIZE]; //height p = mread(p, sizeof(uchar), s); met->height = (uchar)strtol(s,(char**)NULL,16); //width p = mread(p, sizeof(uchar), s); met->width = (uchar)strtol(s,(char**)NULL,16); //horiBearingX p = mread(p, sizeof(char), s); met->offsetx = (char)strtol(s,(char**)NULL,16); //horiBearingY p = mread(p, sizeof(char), s); met->offsety = (char)strtol(s,(char**)NULL,16) - met->height; //horiAdvance p = mread(p, sizeof(uchar), s); met->advance = (uchar)strtol(s,(char**)NULL,16); if(big){ //vertBearingX p = mread(p, sizeof(char), s); //vertBearingY p = mread(p, sizeof(char), s); //vertAdvance p = mread(p, sizeof(uchar), s); } return p; } /* * reading 'name' table * in: on-memory location: top of 'name' * (for out) strings of copyright * (for out) strings of fontname * out: nothing */ void see_name(uchar *nameL, char *copyright, char *fontname){ char s[BUFSIZE]; char *p = nameL; ushort numRecord, storageoff; int i, j; //make copyright/fontname string have priority(level). str_info sright[LEVELCOPYRIGHTSTR]; str_info sname[LEVELFONTNAMESTR]; for(i=0; i<LEVELCOPYRIGHTSTR; i++) sright[i].slen = 0; for(i=0; i<LEVELFONTNAMESTR; i++) sname[i].slen = 0; /* * reading header of 'name' table */ p = mread(p, sizeof(ushort), s); //format selector //number of name records p = mread(p, sizeof(ushort), s); numRecord = (ushort)strtol(s,(char**)NULL,16); //offset from 'name'top to string storage p = mread(p, sizeof(ushort), s); storageoff = (ushort)strtol(s,(char**)NULL,16); /* * reading nameRecords */ for(i=0; i<numRecord; i++){ ushort platformid, specificid, langid, nameid, slen, soff; //PlatformID p = mread(p, sizeof(ushort), s); platformid = (ushort)strtol(s,(char**)NULL,16); //Platform-specificID p = mread(p, sizeof(ushort), s); specificid = (ushort)strtol(s,(char**)NULL,16); //LanguageID p = mread(p, sizeof(ushort), s); langid = (ushort)strtol(s,(char**)NULL,16); //NameID p = mread(p, sizeof(ushort), s); nameid = (ushort)strtol(s,(char**)NULL,16); //String Length p = mread(p, sizeof(ushort), s); slen = (ushort)strtol(s,(char**)NULL,16); //string storage offset from start of storage area p = mread(p, sizeof(ushort), s); soff = (ushort)strtol(s,(char**)NULL,16); if(platformid==1 && langid==0){ //Macintosh, ???(0==Roman), English if(nameid==0){ //Copyright // priority 0 (highest) sright[0].strL = nameL + storageoff + soff; sright[0].slen = slen; }else if(nameid==6){ //fontname (postscript) sname[0].strL = nameL + storageoff + soff; sname[0].slen = slen; }else if(nameid==4){ //fontname (full fontname) sname[1].strL = nameL + storageoff + soff; sname[1].slen = slen; } }else if(platformid==1){ //Macintosh, ???(0==Roman), ???(0x0411=Japanese) if(nameid==0){ sright[1].strL = nameL + storageoff + soff; sright[1].slen = slen; }else if(nameid==6){ sname[2].strL = nameL + storageoff + soff; sname[2].slen = slen; }else if(nameid==4){ sname[3].strL = nameL + storageoff + soff; sname[3].slen = slen; } }else if(platformid==3 && langid==0x0409){ //Microsoft, ???, English if(nameid==0){ sright[2].strL = nameL + storageoff + soff; sright[2].slen = slen; }else if(nameid==6){ sname[4].strL = nameL + storageoff + soff; sname[4].slen = slen; }else if(nameid==4){ sname[5].strL = nameL + storageoff + soff; sname[5].slen = slen; } }else if(platformid==3){ //Microsoft, ???, ???(0x0411==Japanese) if(nameid==0){ sright[3].strL = nameL + storageoff + soff; sright[3].slen = slen; }else if(nameid==6){ sname[6].strL = nameL + storageoff + soff; sname[6].slen = slen; }else if(nameid==4){ sname[7].strL = nameL + storageoff + soff; sname[7].slen = slen; } } /* * assign copyright string */ for(j=0; j<LEVELCOPYRIGHTSTR; j++){ if(sright[j].slen && strcmp(copyright,STRUNKNOWN)==0) copystr(copyright, sright[j].strL, sright[j].slen, 0); } /* * assign fontname string */ for(j=0; j<LEVELFONTNAMESTR; j++){ if(sname[j].slen && strcmp(fontname,STRUNKNOWN)==0) copystr(fontname, sname[j].strL, sname[j].slen, 1); } } } /* * assign string with convert non-ascii character to ascii-character * in: destination pointer * on-memory location: top of string * length of string * this string is for filename or not? (1==yes, 0==no) * out: nothing */ void copystr(char *dst, uchar *src, ushort len, int forFilename){ int i; memset(dst, 0x00, MAXSTRINGINBDF); for(i=0; i<len; i++){ uchar s = *(src+i); if(s==0xa9){ memcpy(dst, "(c)", 3); dst+=3; }else if(s==0xae){ memcpy(dst, "(r)", 3); dst+=3; }else if(forFilename && (s=='?' || s=='*' || s=='/' || s=='\\' || s==':' || s==';' || s=='|' || s=='<' || s=='>' || s==0x22)){ ; //ignore (unable to use as filename in Microsoft Windows) }else if(s<0x20 || s>0x7e){ ; //ignore (probably, Unicode first byte) }else{ *dst = s; dst++; } } *dst='\0'; } //end of file
the_stack_data/266409.c
#include <assert.h> int main() { int *p, v, x, x_before; x_before = x; p = &x; int result = __sync_fetch_and_add(p, v); assert(result == x_before); assert(x == x_before + v); return 0; }