"I freed a thousand slaves. I could have freed a thousand more if only they knew they were slaves." "Eu libertei um mil escravos. Podia ter libertado mais de mil se só eles sabiam que eram escravos."-- Harriet Tubman - Harriet Tubman
A First Look at RedcodeUm primeiro olhar para Redcode
Published by: apples , on 2008-06-20 01:22:40 Publicado por: maçãs, em 2008-06-20 01:22:40
I. Introduction I. Introdução Recently, I ran across a programming-oriented game by the name of "Core War." Recentemente, eu corri em toda uma programação orientada para os jogos com o nome de "Core War". The objective of Core War is to create a program (called a "warrior") that survives the O objetivo do Núcleo Guerra é criar um programa (chamado de "guerreiro") que sobrevive a longest within the Memory Array Redcode Simulator, or MARS for short. há mais tempo no interior da Memória Redcode Array Simulator, ou MARS para breve.However, creating No entanto, criando a warrior is a daunting task, and has a steep learning curve for beginners. um guerreiro é uma tarefa difícil, e tem uma curva de aprendizagem bastante acentuada para os principiantes.In this brief Nesta breve guide, I shall explain the basics of the Redcode assembly language, and give you some tips guia, passo a explicar os conceitos básicos da linguagem Redcode montagem, e dar-lhe algumas dicas on how to create a successful warrior. sobre como criar um bom guerreiro.
II. The Redcode Intsruction Set O set Redcode Intsruction The following section will describe each instruction that is available within the A secção seguinte irá descrever cada instrução que está disponível dentro do Redcode assembly language. Redcode montagem língua.The syntax of any instruction is as follows: A sintaxe de qualquer instrução é a seguinte: CODE : CÓDIGO:
name source, destnome fonte, dest
A. The ADD instruction A. A instrução ADD Well, if you haven't figured out what this one does yet, I'm not sure if Bem, se você ainda não descobri o que faz ainda um presente, não tenho certeza se you should be reading this guide. você deve estar lendo este guia.ADD adds together the source and dest, ADD acrescenta a fonte em conjunto e dest, and stores it in dest. e armazena-la em dest. B. The CMP instruction B. A instrução CMP CMP compares the instruction at source and the instruction at dest, and CMP compara a instrução na fonte e da instrução em dest, e skips the next instruction if they are equal. salta a próxima instrução se eles são iguais. C. The DAT instruction C. A instrução DAT This instruction is vital to winning any Core War game. Esta instrução é vital para vencer qualquer jogo War Core.Upon executing a Após a execução de uma DAT, the warrior will terminate, and will be out of the game. DAT, o guerreiro irá encerrar, e estará fora do jogo.This is one Esta é uma of the only ways to kill a warrior. a única maneira de matar um guerreiro.The arguments to this instruction have Os argumentos para esta instrução têm no effect on how it executes. nenhum efeito sobre o modo como ela executa. D. The DIV instruction D. A instrução DIV As you might have guessed, DIV divides the source by dest, and stores it in Como você pode ter adivinhado, a nascente pela clivagens DIV dest, e armazena-la em dest. If the divisor is 0, the warrior will terminate, as if it has received Se o divisor for 0, o guerreiro irá encerrar, como se ela recebeu a DAT. um DAT. E. The DJN instruction E. A instrução DJN DJN is a conditional jump, the opposite of an unconditional one. DJN é um salto condicional, o oposto de um incondicional um.Conditional Condicional jumps only jump if a certain condition is met. salta só salto se uma certa condição seja cumprida.DJN decrements src by 1, and Src DJN decrementos por 1, e if it is not zero, then it jumps to dest. se não for zero, então ele pula para dest. F. The JMP instruction F. A instrução JMP This is an unconditional jump. Este é um salto incondicional.That means, no matter what, the next instruction Isso significa que, não importa o que aconteça, a próxima instrução executed will be at src. Serão executadas em src. G. The JMN instruction G. A instrução JMN JMN is a conditional jump that checks to is if src is 0, and if it isn't, jumps JMN é um salto condicional que verifica se está a src é 0, e se não for, saltos to dest. para dest. H. The JMZ instruction H. A instrução JMZ JMZ is a conditional jump that checks to is if src is 0, and if it IS, JMZ é um salto condicional que verifica se está a src é 0, e se for, (the opposite of JMN) then it jumps to dest. (o oposto da JMN), em seguida, ele pula para dest. I. The MOD instruction I. A instrução MOD MOD is a modulus function that takes the remainder of a division between src MOD é um módulo função que toma conta do remanescente de uma divisão entre src and dest and stores it in dest. e dest e armazena-la em dest.If the divisor is 0, the same action will be taken as Se o divisor for 0, a mesma ação será tomada como if it were a DIV. se fosse uma DIV. J. The MOV instruction J. A instrução MOV MOV, well, moves the instruction at src to dest. MOV, assim, se desloca para a instrução em src dest.It's easily the most simple instruction É sem dúvida a mais simples instrução in any assembly language. montagem em qualquer idioma. K. The MUL instruction K. O ensino mul MUL multipilies src by dest, and stores the result in dest. MUL multipilies src por dest, e armazena o resultado no dest. L. The SEQ instruction L. A instrução seq SEQ is exactly the same as the aforementioned CMP instruction. SEQ é exatamente o mesmo que a referida instrução CMP. M. The SNE instruction M. instrução do PND SNE compares the instruction at source and the instruction at dest, and PND compara a instrução na fonte e da instrução em dest, e skips the next instruction if they are not equal. salta a próxima instrução se não forem iguais. N. The SPL instruction N. A instrução SPL SPL is the most complicated instruction within all of Redcode. SPL é o mais complicado de todos dentro de instrução Redcode.It starts a new Começa um novo process at the location given by src, and the current process continues towards processo no local determinado pela src, e que o actual processo continua rumo the next instruction. a próxima instrução. O. The SUB instruction O. O sub instrução SUB subtracts src from dest and stores it in dest. SUB subtracções src partir dest e armazena-la em dest.
III. Facts about the MARS system Fatos sobre o sistema MARS MARS works very differently than a regular PC. MARS funciona de maneira muito diferente do que um PC normal.Its memory wraps around, which means Moldado em torno de sua memória, o que significa once you reach the limit of the memory, you start back again at 0. assim que alcançar o limite da memória, você começa novamente a 0.Also, MARS uses what is called Além disso, usa o que é chamado MARS "relative addressing." "parente abordando".This means that in your instructions, you refer to other instructions relative to Isto significa que, no seu manual de instruções, que remetem para outras instruções relativas ao your location. sua localização.An example would be in the first warrior created by AK Dewdney, known as the "Imp." Um exemplo seria no primeiro guerreiro criado pela AK Dewdney, conhecido como o "Imp." The code for the Imp is as follows: O código para o Imp é a seguinte: CODE : CÓDIGO:
MOV $0, $1MOV $ 0, $ 1
Let's dissect what exactly this instruction is doing. Vamos analisar o que está fazendo exatamente esta instrução.First, it's a MOV instruction, so we know that it's Em primeiro lugar, é uma instrução MOV, por isso sabemos que ele é moving an instruction from one place to another. uma instrução que se deslocam de um lugar para outro.The $ sign before the numbers simply means it's "direct", O sinal $ antes do número significa simplesmente que é "directa", which we will cover in the next chapter. que irá abranger, no próximo capítulo.This code moves the instruction at the current location, 0, Este código move a instrução na posição actual, 0, (which is MOV $0, $1) to 1, which is 1 instruction above the current location. (que é MOV $ 0, $ 1) a 1, que é 1 instrução acima do local atual.So, the Imp simply moves Então, o Imp simplesmente jogadas itself to the next instruction indefinitely. -se para a próxima instrução indefinidamente.This tactic easily overwrites the opposing warrior, but will not Essa tática facilmente substitui o oponente guerreiro, mas não vai kill it, so the game will end in a tie. matá-lo, por isso o jogo vai terminar em um empate.
IV. The addressing modes Os modos de endereçamento Addressing modes are certain modes applied to src and dest (from now on known as the A-field Modos de endereçamento são aplicados a determinados modos src e dest (a partir de agora conhecido como o A-campo and the B-field, respectively) that change how an instruction executes. e os B-campo, respectivamente) que a mudança como uma instrução executa.When the rules for Core War Quando as regras para Core War were first written in 1988, only 4 addressing modes were established. Foram primeiro escrito em 1988, apenas 4 modos de endereçamento foram estabelecidos.Later, in 1994, 4 more addressing modes Mais tarde, em 1994, mais 4 modos de endereçamento were added. Foram adicionados.The changes present in the 1994 addition to the Core War rules are known as the '94 standard. As alterações presentes no 1994 para além do Core Guerra regras são conhecidas como as'94 padrão. A. The # (immediate) addressing mode A. O # (imediata) Modo de endereçamento # is used to show that the number is actually a number, and not a reference to another # É usado para mostrar que o número é, na verdade, um número, e não uma referência a outro area. área.ADD #2, @1 would add the number 2 to the B-Field of the instruction at 1. ADD # 2, 1 @ acrescentaria o número 2 para o B-Campo da instrução no 1. B. The $ (direct) addressing mode B. A $ (directo) Modo de endereçamento $ is to display that you explicitly specify the whole instruction. $ É para mostrar que você especificar explicitamente toda a instrução.MOV $0, $1 moves the MOV $ 0, $ 1 move o whole instruction to the location in front of it. toda a instrução para a localização na frente dela.Usually $ can be omitted in your code. Normalmente $ pode ser omitido em seu código. C. The * (A-field indirect) addressing mode C. A * (A-campo indirectos) Modo de endereçamento * shows that you want to take the value stored in the A-field of that instruction. * Revela que pretende tomar o valor armazenado no A-campo do que instrução. MUL *1, #2 will multiply the A-field of the instruction at 1 by the number 2. MUL * 1, # 2, irão multiplicar-se os do campo de instrução no 1 pelo número 2. D. The @ (B-field indirect) addressing mode D. O @ (B-campo indirectos) Modo de endereçamento This is the exact same as the *, except instead of referencing the value in the A-field, Este é exatamente o mesmo que o *, exceto em vez de referenciar o valor na A-campo, you're referencing the one in the B-field. você está referenciando a uma no B-campo. E. The { (A-field indirect with predecrement) mode E. O ((A-campo indireta com predecrement) mode This is similar to the * mode, except that the value stored in the A-field of that instruction Este é parecido com o modo *, exceto que o valor armazenado no A-campo da instrução que is decremented before the current instruction is executed. é diminuída perante a actual instrução for executada. F. The < (B-field indirect with predecrement) mode F. O <(B-campo indireta com predecrement) mode Again, this is exactly the same as the { addressing mode, but with the B-field instead. Novamente, isso é exatamente o mesmo que a (abordando modo, mas com o B-campo em seu lugar. G. The } (A-field indirect with postincrement) mode G. A) (A-campo indireta com postincrement) mode This is the same as the * mode, except after the current instruction is executed, the Este é o mesmo que o * modo, exceto após a instrução atual é executado, a value stored at the A-field of that instruction is inremented by 1. Um valor armazenado no campo de instrução de que é inremented por 1. H. The > (B-field indirect with postincrement) mode H. A> (B-campo indireta com postincrement) mode I'm sure by now you can guess what this mode does. Tenho certeza de que agora você pode adivinhar o que faz deste modo. :)
V. A final warrior example V. Um último exemplo guerreiro This warrior is the second one created by AK Dewdney, and known as the "Dwarf." Este guerreiro é o segundo um AK criado por Dewdney, e conhecida como o "anão".The dwarf O anão places DATs at intervals of 4 within the core. Locais DATs, em intervalos de 4 dentro do núcleo.The following is the code for the dwarf. A seguir está o código para o anão. CODE : CÓDIGO:
Firstly, 4 is added to the B-field of the DAT instruction. Em primeiro lugar, é acrescentado à 4-B campo da instrução DAT.Then, the DAT is copied to 4 instructions in front Em seguida, a DAT é copiado para 4 instruções em frente of itself. de si próprio.Finally, the jump moves back 2 instructions, and 4 is added to the B-field in the DAT again. Finalmente, o salto se move para trás 2 instruções, e 4 é acrescentado à B-campo na DAT novamente.So, the Dwarf Então, o Anão simply copies DATs at 4, 8, 12, etc until it wraps around and starts copying all over again. simplesmente copia DATs em 4, 8, 12, etc até que ele envolve cerca de copiar e começa tudo de novo.This type of warrior Este tipo de guerreiro is known as a "bomber." é conhecida como uma "bomba".There are other types of warriors that will be discussed in a later article. Existem outros tipos de guerreiros que vão ser discutidos em um artigo posterior.
VI. Epilogue Epílogo Redcode is a very interesting language, to say the least. Redcode é uma linguagem muito interessante, para dizer o mínimo.It allows a programmer to hone his skills and Ela permite que um programador para aprimorar suas habilidades e compete at the same time. competir ao mesmo tempo.Hopefully, you've learned a thing or two from this article. Com sorte, você já aprendeu uma coisa ou duas a partir deste artigo.If not, I'm sure it was at least Se não, eu tenho certeza que era pelo menos a good review. uma boa revisão.
Cast your vote on this article Elenco seu voto sobre este artigo *Note: the order of the votes has been reversed. * Nota: a ordem das votações foi revertida.
greyhat_i386 - 02:13 am Friday June 20th, 2008greyhat_i386 - 02h13 sexta-feira 20 de junho de 2008
Good work, must've taken a little while to write and put together. Bom trabalho, must've tido pouco tempo para escrever e todos juntos.A thing or two was learned indeed. Uma coisa ou outra foi aprendido na verdade.
Tiak - 01:51 pm Saturday June 21st, 2008Tiak - 01:51 pm sabado 21 de junho, 2008
I like the article, but the formatting is ugly now that it's posted. Gostei do artigo, mas a formatação é feio agora que ela está postada.
shone - 05:48 pm Saturday June 21st, 2008brilhou - 05:48 pm sabado 21 de junho, 2008
Great article, real refreshment. Excelente artigo, verdadeiro refresco.I didn't know about this 'till now, but it sounds pretty interesting indeed. Eu não sei sobre esse 'até agora, mas soa bastante interessante, de fato.Great work! Grande trabalho!
apples - 02:34 pm Sunday June 22nd, 2008maçãs - 02:34 hs domingo 22 junho, 2008
yeah, Tiak. sim, Tiak.it was all nice and shiny, until HTS went and b0rked it up. Era tudo bonito e brilhante, até HTS b0rked e correu até ele.leave it to HTS to do something like that :P HTS-lo a deixar de fazer algo assim: P
TheMindRapist - 12:15 am Monday June 23rd, 2008TheMindRapist - 12:15 am Segunda-feira 23 de junho de 2008
Seeing as you are a dev why don't you fix it. Já que você é um dev por que você não corrigi-lo. :p : p
shone - 07:23 pm Monday June 23rd, 2008brilhou - 07:23 hs Segunda-feira 23 de junho de 2008
Hey, apples, there is an error in "Dwarf" example: the first line of code should be "ADD #4, 3", not "ADD #4, @3". Ei, maçãs, existe um erro de "anão" exemplo: a primeira linha de código deve ser "ADD # 4, 3", não "ADD # 4, 3 @".That's how it was in the original "Dwarf" code. É assim que o era no original "anão" código.This way the code will not run properly. Desta forma o código não será executado adequadamente.
apples - 10:35 am Tuesday June 24th, 2008maçãs - 10:35 terça-feira 24 de junho de 2008
fixed! fixo!thanks, i never would've noticed. Obrigado, eu nunca teria Notámos.i'm curious as to why it doesn't work though, seeing as how it ends up adding to the B-field anyways. Estou curioso sobre o motivo por que ele não funciona bem que, vendo, o modo como se acaba juntando-se à B-campo mesmo assim.
youssef k - 11:50 pm Friday August 01st, 2008youssef k - 11:50 h Sexta-feira agosto 01o, 2008
good work brother, bom trabalho irmão, keep doing!! continuar a fazer! :)
hadik - 12:12 pm Tuesday August 26th, 2008hadik - 12:12 terça-feira 26 de agosto de 2008
good work dude bom trabalho cara
webdracula - 04:07 am Friday August 29th, 2008webdracula - 04h07 sexta-feira 29 de agosto de 2008
Really helpfull, thank you. Realmente útil, muito obrigado.
Sticksnstoned - 07:35 pm Saturday November 15th, 2008Sticksnstoned - 07:35 hs Sabado 15 de novembro de 2008
where can i get the game? Onde posso comprar o jogo?
This site is the collective work of the HackThisSite staff. Este site é o trabalho coletivo da equipe HackThisSite.Please don't reproduce in part or whole without permission. Por favor, não reproduzir, total ou parcial, sem a sua permissão. Page Generated: Mon, 01 Dec 2008 20:21:26 -0500 Exec: 10 Página Criado em: Mon, 01 dezembro 2008 20:21:26 -0500 Exec: 10 Page loaded in 0.11338 seconds!Página carregada em 0,11338 segundos!
Good work, must've taken a little while to write and put together. Bom trabalho, must've tido pouco tempo para escrever e todos juntos. A thing or two was learned indeed. Uma coisa ou outra foi aprendido na verdade.