Re: Prepisivanje domaceg zadatka
U vezi sa ovom temom, evo odgovora na neka pitanja i primedbe:
Obavestenje da ce oktobarska postavka biti ista kao septembarska
stiglo vam je na dan predaje septembarskog domaceg 2.9. Ispit u
septembru je bio 10.9. Zbog ovog i nacina predaje domaceg izvori prepisivanja su nesumnjivo ucestvovali u prevari. S obzirom da
su izvori ipak uradili resenje, dozvoljava im se izlazak na ispit,
ali domaci se boduje sa 5 poena manje.
Domaci radovi se mogu kompletno oceniti bez usmene odbrane,
posto predata resenja sadrze sve elemente za ocenu. Usmena
odbrana je jedan od nacina da se utvrdi da li je student samostalno
radio domaci, kao i uporedjivanje razlicitih resenja i moze ali
ne mora biti sprovedena, pri cemu studenti unapred ne moraju
biti upoznati sa time da li ce nje biti ili ne, za sve ili neke
studente.
Za studente koji se nalaze na listi a tvrde da nisu prepisivali,
u nastavku slede karakteristicni fragmenti koda iz kojih se
jasno vidi da se razlikuju samo u imenima promenljivih.
Ako se identifikuje ko je izvor a ko prepisivac, onda vazi gornja
napomena za "izvor", inace se svi tretiraju kao prepisivaci.
DB
Petrovic Darko
==============
public void work() throws DisassemblerException {
//Load the source file from the disk;
ofl.load();
//Is the loaded file as it should be?
ConsistencyChecker.check(ofl);
//Yes? Let's open the output file and generate some assembly code.
afw = new AssemblyFileWriter(outputFileName);
//Should I begin with ORG or with BEG?
if(ofl.ORGused()) {
location = ofl.getSegBase((byte)1);
afw.write(location, "", "", "ORG", Integer.toString(ofl.getSegBase((byte)1)));
}
else afw.write(location, "", "", "BEG", "");
//Any global symbols defined or used?
String def = "", use = "";
int defined = ofl.definedSymbolsNo();
int used = ofl.usedSymbolsNo();
for(byte i=1; i<=ofl.symbolsNo(); i++) {
switch(ofl.getSymType(i)) {
case 'D': def = def.concat(ofl.getSymName(i));
if(--defined!=0) def = def.concat(", "); break;
case 'U': use = use.concat(ofl.getSymName(i));
if(--used!=0) use = use.concat(", "); break;
}
}
if(def!="") afw.write(location, "", "", "DEF", def);
if(use!="") afw.write(location, "", "", "USE", use);
//Now comes the main thing - the data. We pass through all segments, one by one.
int segno = ofl.segmentsNo();
for(int seg=1; seg<=segno; seg++) {
//Is the segment present? In other words, is it text or data segment?
//Obviously, if it isn't, it is a BSS segment for sure.
if((ofl.getSegDesc(seg)).contains("P")) {
afw.write(location, "", "", ofl.getSegName(seg).equals(".text")?"TXT":"DAT", "");
//Does any relocation refer to this segment?
//If answer is positive, we'll need a label for it.
int rno = ofl.relocNo();
for(int rel=1; rel<=rno; rel++) {
if(ofl.getRelocRef(rel)==seg && ofl.getRelocType(rel).equals("A1")) {
afw.write(location, "", "SEG"+seg, "", "");
break;
}
}
//We have to pass through the segment and disassemble the data.
boolean opcode = ofl.getSegName(seg).equals(".text"); //text segment begins with opcode
boolean secondByte = false; //true when second byte of instruction is being operated
String mnem=""; byte code=0; //mnemonic information for current instruction
int segEnd = ofl.getSegLength(seg)+ofl.getSegBase(seg)-1;
locationLoop: for(;location<=segEnd; location++) {
//Before the data is finally read, let's check if there are symbols
//defined on this location.
//If current location is the second byte of some instruction,
//there shouldn't be any of them.
int symno = ofl.symbolsNo();
for(byte sym=1; sym<=symno; sym++) {
if(ofl.getSymSegment(sym)!=0 && ofl.getSymValue(sym)==location && ofl.getSymType(sym)=='D') {
if(!secondByte) afw.write(location, "", ofl.getSymName(sym), "", "");
else throw new SymbolOnAddressFieldException(ofl.getSymName(sym));
}
}
//Is the byte, which is about to be read, relocative or not?
boolean relocInfoFound = false;
for(int rel=1; rel<=rno; rel++) {
byte loc = ofl.getRelocLoc(rel);
byte ref = ofl.getRelocRef(rel);
String type = ofl.getRelocType(rel);
if(loc == location) {
//location with opcode cannot be relocated
if(opcode) throw new OperationCodeRelocationException();
if(type.equals("A1")) { //A1 reloc info found for this location
byte refBase = ofl.getSegBase(ref);
int hex = ofl.getData(seg,location-ofl.getSegBase(seg));
int dat = hex - refBase;
String addr = "SEG"+ref;
if(dat>0) addr=addr.concat("+"+dat);
else if(dat<0) addr=addr.concat(""+dat);
String dbl =Integer.toHexString(code)+" "+Integer.toHexString(hex);
if(secondByte) {
afw.write((byte)(location-1), dbl, "", mnem, addr);
secondByte = false; opcode = true;
continue locationLoop;
}
else afw.write(location, Integer.toHexString(hex) , "", "DC", addr);
} else if(type.equals("AS1")) { //AS1 reloc info found for this location
String addr = ofl.getSymName(ref);
byte displ = ofl.getData(seg, location-ofl.getSegBase(seg));
if(displ>0) addr=addr.concat("+"+displ);
else if(displ<0) addr=addr.concat(""+displ);
String dbl =Integer.toHexString(code)+" "+Integer.toHexString(displ);
if(secondByte) {
afw.write((byte)(location-1), dbl, "", mnem, addr);
secondByte = false; opcode = true;
continue locationLoop;
}
else afw.write(location, Integer.toHexString(displ), "", "DC", addr);
}
relocInfoFound = true;
break;
}
}
//if this is second byte and no relocations found, write the line and go to next one
if(secondByte) {
byte addr = ofl.getData(seg, location-ofl.getSegBase(seg));
String dbl =Integer.toHexString(code)+" "+Integer.toHexString(addr);
afw.write((byte)(location-1), dbl, "", mnem, addr+"");
secondByte = false; opcode = true;
continue locationLoop;
}
if(opcode) {
//take operation code, disassemble mnemonic
code = ofl.getData(seg, location-ofl.getSegBase(seg));
mnem = getMnemonic(code);
//write instruction, or prepare for next byte if necessary
secondByte = (code>=0x19);
opcode = !secondByte;
if(!secondByte) afw.write(location,Integer.toHexString(code), "", mnem, "");
} else if(!relocInfoFound){
//if no relocations for this non-opcode location, just place the byte to the address field
byte dat = ofl.getData(seg, location-ofl.getSegBase(seg));
afw.write(location,Integer.toHexString(dat), "", "DC", Integer.toString(dat));
}
} //location end
} else { //BSS segment
afw.write(location, "", "", "BSS", "");
//Any symbols here?
int symno = ofl.symbolsNo();
for(byte sym=1; sym<=symno; sym++) {
if(ofl.getSymValue(sym)==location && ofl.getSymType(sym)=='D') {
afw.write(location, "", ofl.getSymName(sym), "", "");
}
}
//Does any relocation refer to this segment?
//If answer is positive, we'll need a label for it.
int rno = ofl.relocNo();
for(int rel=1; rel<=rno; rel++) {
if(ofl.getRelocRef(rel)==seg && ofl.getRelocType(rel).equals("A1")) {
afw.write(location, "", "SEG"+seg, "", "");
break;
}
}
//The only thing we have to do is to write a DS directive.
afw.write(location, "", "", "DS", Integer.toString(ofl.getSegLength(seg)));
location+=ofl.getSegLength(seg);
}
}
//writing EQU directives (absolute symbols)
int symno = ofl.symbolsNo();
for(byte sym=1; sym<=symno; sym++)
if(ofl.getSymSegment(sym)==0 && ofl.getSymType(sym)=='D')
afw.write(location, "", ofl.getSymName(sym), "EQU", ofl.getSymValue(sym)+"");
//The end! :)
afw.write(location, "", "", "END", "");
afw.close();
}
Knezevic Dusan
==============
public void disassemble() throws Greska {
mem.ucitaj();
Provera.proveri(mem);
izlaz = new Upisivanje(outputFileName);
if(mem.ORG()) {
location = mem.getSegBase((byte)1);
izlaz.pisi(location, "", "", "ORG", Integer.toHexString(mem.getSegBase((byte)1)));
}
else izlaz.pisi(location, "", "", "BEG", "");
//simboli?
String def="", use="";
int used=mem.usedNo();
int defined=mem.defNo();
for(byte i=1; i<=mem.brSimbola(); i++) {
switch(mem.getSymType(i)) {
case 'U':
use=use.concat(mem.getSymName(i));
if(--used!=0) use=use.concat(", ");
break;
case 'D':
def=def.concat(mem.getSymName(i));
if(--defined!=0) def=def.concat(", ");
break;
}
}
if(def!="") izlaz.pisi(location, "", "", "DEF", def);
if(use!="") izlaz.pisi(location, "", "", "USE", use);
//citaj iz tabela i pravi asm
int segno = mem.brSeg();
for(int seg=1; seg<=segno; seg++) {
if((mem.getSegDesc(seg)).contains("P")) {
izlaz.pisi(location, "", "", mem.getSegName(seg).equals(".text")?"TXT":"DAT", "");
int rno = mem.brRelok();
for(int rel=1; rel<=rno; rel++) {
if(mem.getRelocRef(rel)==seg && mem.getRelocType(rel).equals("A1")) {
izlaz.pisi(location, "", "LOCAL"+seg, "", "");
break;
}
}
boolean opcode=mem.getSegName(seg).equals(".text");
boolean l2=false;
String mnem=""; byte code=0;
loop: for(;location<=mem.getSegLen(seg)+mem.getSegBase(seg)-1; location++) {
//simboli?
int symno=mem.brSimbola();
for(byte sym=1; sym<=symno; sym++) {
if(mem.getSymSegment(sym)!=0 && mem.getSymValue(sym)==location && mem.getSymType(sym)=='D') {
if(!l2) izlaz.pisi(location, "", mem.getSymName(sym), "", "");
}
}
//reloc?
boolean relokacija=false;
for(int rel=1; rel<=rno; rel++) {
byte loc=mem.getRelocLoc(rel);
byte ref=mem.getRelocRef(rel);
String type=mem.getRelocType(rel);
if(loc == location) {
if(type.equals("A1")) {
byte refBase=mem.getSegBase(ref);
int hex=mem.getData(seg,location-mem.getSegBase(seg));
int dat=hex - refBase;
String addr="LOCAL"+ref;
if(dat>0) addr=addr.concat("+"+dat);
else if(dat<0) addr=addr.concat(""+dat);
if(l2) {
izlaz.pisi((byte)(location-1), Integer.toHexString(code)+" "+Integer.toHexString(hex), "", mnem, addr);
l2=false; opcode=true;
continue loop;
}
else izlaz.pisi(location, Integer.toHexString(hex) , "", "DC", addr);
} else if(type.equals("AS1")) {
String adr=mem.getSymName(ref);
byte b=mem.getData(seg, location-mem.getSegBase(seg));
if(b>0) adr=adr.concat("+"+b);
else if(b<0) adr=adr.concat(""+b);
if(l2) {
izlaz.pisi((byte)(location-1), Integer.toHexString(code)+" "+Integer.toHexString(b), "", mnem, adr);
l2=false; opcode=true;
continue loop;
}
else izlaz.pisi(location, Integer.toHexString(b), "", "DC", adr);
}
relokacija=true;
break;
}
}
if(l2) {
byte adr=mem.getData(seg, location-mem.getSegBase(seg));
izlaz.pisi((byte)(location-1), Integer.toHexString(code)+" "+Integer.toHexString(adr), "", mnem, adr+"");
l2=false; opcode=true;
continue loop;
}
if(opcode) {
code=mem.getData(seg, location-mem.getSegBase(seg));
mnem=MNE(code);
//pisi
opcode=!(l2=(code>=0x19));
if(!l2) izlaz.pisi(location,Integer.toHexString(code), "", mnem, "");
} else if(!relokacija){
byte dat=mem.getData(seg, location-mem.getSegBase(seg));
izlaz.pisi(location,Integer.toHexString(dat), "", "DC", Integer.toString(dat));
}
}
} else { //BSS
izlaz.pisi(location, "", "", "BSS", "");
//simboli?
int symno=mem.brSimbola();
for(byte sym=1; sym<=symno; sym++) {
if(mem.getSymValue(sym)==location && mem.getSymType(sym)=='D') {
izlaz.pisi(location, "", mem.getSymName(sym), "", "");
}
}
//nova labela
int rno=mem.brRelok();
for(int rel=1; rel<=rno; rel++) {
if(mem.getRelocRef(rel)==seg && mem.getRelocType(rel).equals("A1")) {
izlaz.pisi(location, "", "LOCAL"+seg, "", "");
break;
}
}
//DS
izlaz.pisi(location, "", "", "DS", Integer.toString(mem.getSegLen(seg)));
location+=mem.getSegLen(seg);
}
}
//EQU
int symno=mem.brSimbola();
for(byte sym=1; sym<=symno; sym++)
if(mem.getSymSegment(sym)==0 && mem.getSymType(sym)=='D')
izlaz.pisi(location, "", mem.getSymName(sym), "EQU", mem.getSymValue(sym)+"");
izlaz.pisi(location, "", "", "END", "");
izlaz.close();
}
Prodanovic Vedran
=================
public void checkErrors(){
//segment errors
//Multiple segment definition
for (int i=0;i<segmentTable.size()-1;i++){
SegmentCell segi=(SegmentCell) segmentTable.get(i);
if(segi==null) continue;
for(int j=i+1;j<segmentTable.size();j++){
SegmentCell segj=(SegmentCell) segmentTable.get(j);
if(segj==null) continue;
if(segi!=null && segi.name.equals(segj.name)){
errorTable.addError("error 14 : Multiple definition of segment " + segi.name);
}
}
}
//Description of segment not correct
//Mising data section
int presentSegs=0;
for(int i=0;i<segmentTable.size();i++){
SegmentCell segi=(SegmentCell) segmentTable.get(i);
if(segi==null) continue;
boolean descCorrect=true;
for(int j=0;j<segi.desc.length();j++){
if(segi!=null && !(segi.desc.charAt(j)=='P' || segi.desc.charAt(j)=='R' || segi.desc.charAt(j)=='W')){
descCorrect=false;
}
}
if(!descCorrect){
errorTable.addError("error 15 : Unknown description of segment " + segi.name );
}
if(segi.desc.indexOf("P")>=0) {
String[] mcode=null;
try{
mcode=((String)dataTable.get(presentSegs++)).split(" ");
}
catch(ArrayIndexOutOfBoundsException e){
errorTable.addError("error 16 : Missing data section for segment " +segi.name );
continue;
}
try{
if(mcode.length<segi.len ){
errorTable.addError("error 17 : Data section of segment " +segi.name + " is too short");
}
if(mcode.length>segi.len ){
errorTable.addError("error 18 : Data section of segment " +segi.name + " is too long");
}
}
catch(NullPointerException e){
}
}
}
//symbol errors
//Multiple symbol definition
for (int i=0;i<symbolTable.size()-1;i++){
SymbolCell symi=(SymbolCell) symbolTable.get(i);
if (symi== null) continue;
for(int j=i+1;j<symbolTable.size();j++){
SymbolCell symj=(SymbolCell) symbolTable.get(j);
if (symj==null) continue;
if(symi.name.equals(symj.name)){
errorTable.addError("error 19 : Multiple definition of symbol " + symi.name);
}
}
}
for (int i=0;i<symbolTable.size();i++){
SymbolCell sym=(SymbolCell) symbolTable.get(i);
if(sym==null) continue;
if (sym.type.equalsIgnoreCase("D") && sym.seg <=segmentTable.size()){
SegmentCell s=(SegmentCell) segmentTable.get(sym.seg-1);
if (s!=null && (sym.value<s.base || sym.value>(s.base+s.len -1))){
errorTable.addError("error 20 : Value of symbol " + sym.name + " out of segment " + s.name);
}
}
if (sym.type.equalsIgnoreCase("U")){
if(sym.seg!=0 && sym.value!=0){
errorTable.addError("error 21 : Fields seg and value must be 0 for undefine symbol " +sym.name );
}
}
if(!(sym.type.equalsIgnoreCase("U") || sym.type.equalsIgnoreCase("D"))){
errorTable.addError("error 22 : Unknown type of symbol " + sym.name);
}
if(sym.seg >segmentTable.size()){
errorTable.addError("error 23 : Unknown segment " +sym.seg+ " for symbol " +sym.name );
}
}
//relocation errors
for (int i=0;i<relocationTable.size();i++){
RelocationCell r=(RelocationCell) relocationTable.get(i);
if(r==null) continue;
SegmentCell seg=null;;
if(r.seg > segmentTable.size()){
errorTable.addError("error 24 : Unknown segment "+r.seg +" (" + (i+1)+". line of relocation section)");
}
else{
seg=(SegmentCell) segmentTable.get(r.seg -1);
}
if(seg!=null && (r.loc<seg.base || r.loc
(seg.base + seg.len -1))){errorTable.addError("error 25 : Relocation address " + r.loc + " out of segment " +seg.name);
}
if(r.type.equalsIgnoreCase("A1")){
if(r.ref > segmentTable.size()){
errorTable.addError("error 26 : Unknown field ref "+r.ref +" (" + (i+1)+". line of relocation section)");
}
}
else {
if(r.type.equalsIgnoreCase("AS1")){
if(r.ref > symbolTable.size()){
errorTable.addError("error 26 : Unknown field ref "+r.ref +" (" + (i+1)+". line of relocation section)");
}
}
else{
errorTable.addError("error 27 : Unknown type " +r.type + " (" + (i+1)+". line of relocation section)");
}
}
}
//data section errors
for(int j=0;j<dataTable.size();j++){
String[] mcode=((String)dataTable.get(j)).split(" ");
for(int k=0;k<mcode.length;k++){
try{
Integer.parseInt(mcode[k],16);
//System.out.println("asda");
}
catch(NumberFormatException e){
errorTable.addError("error 28 : Some of fields in data section not a number" );
break;
}
}
}
}
Radovic Marko
=============
public void proveriGreske () {
for (int i=0;i<seg.size()-1;i++){
Segment seg1=(Segment) seg.elementAt(i);
if(seg1==null)
continue;
for(int j=i+1;j<seg.size();j++){
Segment seg2=(Segment) seg.elementAt(j);
if(seg2==null)
continue;
if(seg1!=null && seg1.uzmiIme().equals(seg2.uzmiIme()))
gre.postaviG(9);
}
}
int trenutnaLin=0;
for(int i=0;i<seg.size();i++){
Segment seg1=(Segment) seg.elementAt(i);
if(seg1==null)
continue;
boolean tacanTip=true;
for(int j=0;j<seg1.uzmiTip().length();j++){
if(seg1!=null && !(seg1.uzmiTip().charAt(j)=='P' || seg1.uzmiTip().charAt(j)=='R' || seg1.uzmiTip().charAt(j)=='W'))
tacanTip=false;
}
if(!tacanTip)
gre.postaviG(10);
if (sadrzi(seg1.uzmiTip(),'P')) {
String[] kod1=null;
try{
kod1=((String)pod.elementAt(trenutnaLin++)).split(" ");
}
catch(ArrayIndexOutOfBoundsException e){
gre.postaviG(11);
continue;
}
try{
if(kod1.length!=seg1.uzmiDuzina())
gre.postaviG(12);
}
catch(NullPointerException e){
}
}
}
for (int i=0;i<simb.size()-1;i++){
Simbol simb1=(Simbol) simb.elementAt(i);
if (simb1 == null)
continue;
for(int j=i+1;j<simb.size();j++){
Simbol simb2=(Simbol) simb.elementAt(j);
if (simb2==null)
continue;
if(simb1.uzmiIme().equals(simb2.uzmiIme()))
gre.postaviG(13);
}
}
for (int i=0;i<simb.size();i++){
Simbol simb1=(Simbol) simb.elementAt(i);
if(simb1==null)
continue;
if (simb1.uzmiTip().equals("D") && simb1.uzmiSegment() <=seg.size()){
Segment s=(Segment) seg.elementAt(simb1.uzmiSegment()-1);
if (s!=null && (simb1.uzmiVrednost()<s.uzmiPocetak() || simb1.uzmiVrednost()>(s.uzmiPocetak()+s.uzmiDuzina() -1)))
gre.postaviG(14);
}
if(!(simb1.uzmiTip().equals("U") || simb1.uzmiTip().equals("D")))
gre.postaviG(15);
if(simb1.uzmiSegment()>seg.size())
gre.postaviG(16);
if (simb1.uzmiTip().equals("U") && !(simb1.uzmiSegment()==0 && simb1.uzmiVrednost()==0))
gre.postaviG(17);
}
for (int i=0;i<rel.size();i++){
Relokacija r1=(Relokacija) rel.elementAt(i);
if(r1==null)
continue;
Segment seg1=(Segment) seg.elementAt(r1.uzmiSegment() -1);
if(r1.uzmiSegment() > seg.size())
gre.postaviG(18);
if(seg1!=null && (r1.uzmiLokacija()<seg1.uzmiPocetak() || r1.uzmiLokacija()
(seg1.uzmiPocetak() + seg1.uzmiDuzina() -1)))gre.postaviG(19);
if(r1.uzmiTip().equals("A1")){
if(r1.uzmiRef() > seg.size())
gre.postaviG(20);
}
else {
if(r1.uzmiTip().equals("AS1")){
if(r1.uzmiRef() > simb.size()){
gre.postaviG(21);
}
}
else{
gre.postaviG(22);
}
}
}
for(int i=0;i<pod.size();i++){
String[] kod1=((String)pod.elementAt(i)).split(" ");
for(int j=0;j<kod1.length;j++){
try{
Integer.parseInt(kod1[j],16);
}
catch(NumberFormatException e){
gre.postaviG(23);
break;
}
}
}
}
- Follow-Ups:
- Re: Prepisivanje domaceg zadatka
- From: "Darko Petrovic" <shtreber@gmail.com>
- Re: Prepisivanje domaceg zadatka
- References:
- Prepisivanje domaceg zadatka
- From: Dragan Bojic <bojic@etf.bg.ac.yu>
- Re: Prepisivanje domaceg zadatka
- From: "Darko Petrovic" <shtreber@gmail.com>
- Prepisivanje domaceg zadatka
Previous by date: Re: [etf_2003_rti] Fw: Prepisivanje domaceg zadatka
Next by date: Re: Prepisivanje domaceg zadatka
Previous by thread: Re: Prepisivanje domaceg zadatka Next by thread: Re: Prepisivanje domaceg zadatka
Previous by thread: Re: Prepisivanje domaceg zadatka Next by thread: Re: Prepisivanje domaceg zadatka