add uint toS
This commit is contained in:
		
							parent
							
								
									d9ab352c68
								
							
						
					
					
						commit
						bf2609c6ee
					
				| 
						 | 
				
			
			@ -53,7 +53,7 @@ int main() {
 | 
			
		|||
  memory[i++].u = 103;
 | 
			
		||||
  memory[i++].u = 1;
 | 
			
		||||
  memory[i++].u = 103;
 | 
			
		||||
  memory[i++].u = OP_INT_TO_STRING;
 | 
			
		||||
  memory[i++].u = OP_UINT_TO_STRING;
 | 
			
		||||
  memory[i++].u = 103;
 | 
			
		||||
  memory[i++].u = 1;
 | 
			
		||||
  memory[i++].u = 104;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								src/vm.c
								
								
								
								
							
							
						
						
									
										16
									
								
								src/vm.c
								
								
								
								
							| 
						 | 
				
			
			@ -227,6 +227,22 @@ uint32_t step_vm(Word *memory, uint32_t memory_size, uint32_t pc) {
 | 
			
		|||
    mem_strcpy(memory, buffer + i, MAX_LEN_INT32 - i, dest_addr);
 | 
			
		||||
    return pc;
 | 
			
		||||
  }
 | 
			
		||||
  case OP_UINT_TO_STRING: {
 | 
			
		||||
    uint32_t v = memory[src1_addr].u;
 | 
			
		||||
    char buffer[MAX_LEN_INT32];
 | 
			
		||||
    uint32_t n = v;
 | 
			
		||||
    int i = MAX_LEN_INT32;
 | 
			
		||||
    do {
 | 
			
		||||
      buffer[--i] = radix_set[n % 10];
 | 
			
		||||
      n /= 10;
 | 
			
		||||
    } while (n > 0);
 | 
			
		||||
    /* Ensure at least one digit is written for 0 */
 | 
			
		||||
    if (v == 0)
 | 
			
		||||
      buffer[--i] = '0';
 | 
			
		||||
    /* Copy from buffer[i] to buffer + MAX_LEN_INT32 */
 | 
			
		||||
    mem_strcpy(memory, buffer + i, MAX_LEN_INT32 - i, dest_addr);
 | 
			
		||||
    return pc;
 | 
			
		||||
  }
 | 
			
		||||
  case OP_REAL_TO_STRING: {
 | 
			
		||||
    int32_t q = memory[src1_addr].q;
 | 
			
		||||
    char buffer[32]; /* Max 10 digits for integer part + 6 for fractional + sign
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								src/vm.h
								
								
								
								
							
							
						
						
									
										9
									
								
								src/vm.h
								
								
								
								
							| 
						 | 
				
			
			@ -57,10 +57,11 @@ typedef enum {
 | 
			
		|||
  OP_MOV,            /* dest = src1	   */
 | 
			
		||||
  OP_JMP,            /* jump to address src1 unconditionally */
 | 
			
		||||
  OP_INT_TO_STRING,  /* dest = src1 as str */
 | 
			
		||||
  OP_REAL_TO_STRING, /* dest = src2 as str */
 | 
			
		||||
  OP_READ_STRING,    /* dest = src1 */
 | 
			
		||||
  OP_PRINT_STRING,   /* dest = src1 */
 | 
			
		||||
  OP_CMP_STRING,     /* dest = src1 */
 | 
			
		||||
  OP_UINT_TO_STRING, /* dest = src1 as str */
 | 
			
		||||
  OP_REAL_TO_STRING, /* dest = src1 as str */
 | 
			
		||||
  OP_READ_STRING,    /* dest = read as str */
 | 
			
		||||
  OP_PRINT_STRING,   /* write src1 to stdout */
 | 
			
		||||
  OP_CMP_STRING,     /* dest = src1 as str == src2 as str */
 | 
			
		||||
} Opcode;
 | 
			
		||||
 | 
			
		||||
uint32_t step_vm(Word *memory, uint32_t memory_size, uint32_t pc);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue